Get 50% OFF QuickBooks for 3 months*

Buy now
cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β 
Announcements
Work smarter and get more done with advanced tools that save you time. Discover QuickBooks Online Advanced.

Reply to message

View discussion in a popup

Replying to:
Ralius
Level 2

Reply to message

This is APPALLING. I'm so used to using Freshbooks that I keep trying to go in and change something only to have the entire entry be cleared out! Even a 10 year old could code this better. HERE ILL HAVE GPT DO IT FOR YOU. It's so painfully clear that you don't have actual engineers on deck just a bunch of SEA code jockeys who couldn't program their way out of a paper bag. This software is disgusting and I actually hate it but my accountants put me on here last year and now I have to fight with them to change back to Freshbooks. Competency Crisis is real, folks! You're witnessing it first hand. 

 

Oh yeah here's your code. GO FIX IT. 

 

using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace YourNamespace
{
public class Service
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}

public class YourDbContext : DbContext
{
public DbSet<Service> Services { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Replace with your actual connection string
optionsBuilder.UseSqlServer("YourConnectionString");
}
}

public class ServiceManager
{
private readonly YourDbContext _context;

public ServiceManager(YourDbContext context)
{
_context = context;
}

public async Task AddServiceIfNotExistsAsync(string name, string description)
{
// Check if the service already exists in the database
var existingService = await _context.Services
.Where(s => s.Name == name)
.FirstOrDefaultAsync();

if (existingService == null)
{
// If service does not exist, create and add the new service
var newService = new Service
{
Name = name,
Description = description
};

_context.Services.Add(newService);
await _context.SaveChangesAsync();
Console.WriteLine("Service added to the database.");
}
else
{
Console.WriteLine("Service already exists in the database.");
}
}
}

class Program
{
static async Task Main(string[] args)
{
using (var context = new YourDbContext())
{
var serviceManager = new ServiceManager(context);

// Replace with the name and description of the service you want to check/add
string serviceName = "Example Service";
string serviceDescription = "This is a description of the example service.";

await serviceManager.AddServiceIfNotExistsAsync(serviceName, serviceDescription);
}
}
}
}

Need to get in touch?

Contact us