Пример #1
0
 public async Task Delete(int id) {
     var customer = new Customer {
         Id = id
     };
     Context.Customers.Attach(customer).State = EntityState.Deleted;
     await Context.SaveChangesAsync();
 }
Пример #2
0
 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;
 }
Пример #3
0
 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
     };
 }