public async Task Delete(int id) { var customer = new Customer { Id = id }; Context.Customers.Attach(customer).State = EntityState.Deleted; await Context.SaveChangesAsync(); }
public async Task<int> Save(Customer customer) { if (string.IsNullOrEmpty(customer.Street)) throw new InvalidOperationException("Street is required"); if (customer.IsTransient()) { Context.Customers.Add(customer); } else { Context.Customers.Attach(customer).State = Microsoft.Data.Entity.EntityState.Modified; } await Context.SaveChangesAsync(); return customer.Id; }
public static CustomerModel ToModel(Customer source) { return new CustomerModel { Id = source.Id, Name = source.Name, Street = source.Street, City = source.City, PostalCode = source.PostalCode, Region = source.Region, FiscalIdentifier = source.FiscalIdentifier, SendMailing = source.SendMailing }; }