public static Service AddNew(int Id, string serviceName, float unitPrice, float netPrice, int Vat) { try { using (var context = new ServicesDBEntities()) { var newservice = new Service { ServiceName = serviceName, UnitPrice = unitPrice, NetPrice = netPrice, Vat = Vat, VatAmount = ((Vat * unitPrice) / 100), PretaxPrice = (unitPrice + (Vat * unitPrice) / 100), }; context.Services.Add(newservice); context.SaveChanges(); return newservice; } } catch (Exception ex) { return null; } }
public static Customer GetById(int id, bool loadReferences = false) { try { using (var context = new ServicesDBEntities()) { if (loadReferences) { return context.Customers .Where(p => p.Id == id) .FirstOrDefault(); } else { return context.Customers .Where(p => p.Id == id) .FirstOrDefault(); } } } catch (Exception ex) { return null; } }
public static Customer AddNew(string name, string surname, string companyName, string street, string city, int code, int? phoneNumber, int NIP) { try { using (var context = new ServicesDBEntities()) { var newPerson = new Customer { Name = name, Surname = surname, CompanyName = companyName, Street = street, City = city, Code = code, PhoneNumber = phoneNumber, NIP = NIP }; context.Customers.Add(newPerson); context.SaveChanges(); return newPerson; } } catch (Exception ex) { return null; } }
public static List<Seller> GetList() { try { using (var context = new ServicesDBEntities()) { return context.Sellers.ToList(); } } catch (Exception ex) { return new List<Seller>(); } }
public static Seller GetById(int id) { try { using (var context = new ServicesDBEntities()) { var record = context.Sellers .Where(p => p.Id == id) .FirstOrDefault(); return record; } } catch (Exception ex) { return null; } }
public static Customer Delete(int projectId) { try { using (var context = new ServicesDBEntities()) { var deleteServive = (context.Services .Where(p => p.Id == projectId) .FirstOrDefault()); context.Services.Remove(deleteServive); context.SaveChanges(); return null; } } catch (Exception ex) { return null; } }
private static List<Customer> GetList() { try { using (var context = new ServicesDBEntities()) { return context.Customers.ToList(); } } catch (Exception ex) { return new List<Customer>(); } }
public static Service Edit(int Id, string serviceName, float unitPrice, float netPrice, int VAT) { try { using (var context = new ServicesDBEntities()) { var editService = (context.Services .Where(p => p.Id == Id) .FirstOrDefault()); editService.ServiceName = serviceName; editService.UnitPrice = unitPrice; editService.NetPrice = netPrice; editService.Vat = VAT; context.SaveChanges(); return editService; }; } catch (Exception ex) { return null; } }
public static List<Service> GetServiceByIds(List<int> servicesId) { try { using (var context = new ServicesDBEntities()) { var services = from c in context.Services where servicesId.Contains(c.Id) select c; var allServices = services.ToList(); var sortedCustomers = new List<Service>(); foreach (int id in servicesId) { var service = allServices.Find(x => x.Id == id); if (service != null) sortedCustomers.Add(service); } return sortedCustomers; } } catch (Exception ex) { return null; } }
public static Customer Edit(int Id, string name, string surname, string companyName, string street, string city, int code, int? phoneNumber, int NIP) { try { using (var context = new ServicesDBEntities()) { var editPerson = (context.Customers .Where(p => p.Id == Id) .FirstOrDefault()); editPerson.Name = name; editPerson.Surname = surname; editPerson.CompanyName = companyName; editPerson.Street = street; editPerson.City = city; editPerson.Code = code; editPerson.PhoneNumber = phoneNumber; editPerson.NIP = NIP; context.SaveChanges(); return editPerson; }; } catch (Exception ex) { return null; } }
public static Customer GetCustomerName(string name) { try { using (var context = new ServicesDBEntities()) { var record = context.Customers .Where(p => p.Name == name) .FirstOrDefault(); return record; } } catch (Exception ex) { return null; } }