public Product Create(Product product) { var productInDB = _context.Products.FirstOrDefault(a => a.Name.Trim().ToUpper() == product.Name.Trim().ToUpper()); if (productInDB == null) { _context.Products.Add(product); } else { if ( product.Description.ToUpper() != productInDB.Description.ToUpper() || product.Price != productInDB.Price ) { productInDB.Description = product.Description; productInDB.Price = product.Price; _context.Update(productInDB); } } _context.SaveChanges(); return(product); }
public Customer Create(Customer customer) { var customerInDB = _context.Customers.FirstOrDefault(a => a.Email.Trim().ToUpper() == customer.Email.Trim().ToUpper()); if (customerInDB == null) { _context.Customers.Add(customer); } else { if ( customer.Name.ToUpper() != customerInDB.Name.ToUpper() || customer.Password != customerInDB.Password ) { customerInDB.Name = customer.Name; customerInDB.Password = customer.Password; _context.Update(customerInDB); } } _context.SaveChanges(); return(customer); }