public static void AddCustomer(CustomerDTO dto) { using (var db = new WebDBEntities()) { var customer = new Customer { Name = dto.Name, Surname = dto.Surname, Phone = dto.Phone, Email = dto.Email }; db.Customers.Add(customer); db.SaveChanges(); } }
public static void UpdateCustomer(CustomerDTO customerDto) { using (var db = new WebDBEntities()) { var customer = db.Customers.FirstOrDefault(r => r.Id == customerDto.Id) ?? new Customer { Id = customerDto.Id }; customer.Name = customerDto.Name; customer.Surname = customerDto.Surname; customer.Email = customerDto.Email; customer.Phone = customerDto.Phone; db.Customers.AddOrUpdate(customer); db.SaveChanges(); } }
public ActionResult Edit(CustomerDTO customerDto) { Helper.UpdateCustomer(customerDto); return RedirectToAction("Index"); }
public static CustomerDTO GetCustomer(int id) { using (var db = new WebDBEntities()) { var customer = db.Customers.FirstOrDefault(r => r.Id == id); if (customer == null) throw new ArgumentException("Неверное значение параметра", nameof(id)); var customerDTO = new CustomerDTO { Id = customer.Id, Name = customer.Name, Surname = customer.Surname, Phone = customer.Phone, Email = customer.Email }; return customerDTO; } }
public ActionResult Add(CustomerDTO customerDto) { Helper.AddCustomer(customerDto); return RedirectToAction("Index"); }