public async Task <CustomerDto> UpdateCustomer(int id, CustomerDto customerDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (id != customerDto.CustomerId) { return(null); } else { Customer cs = db.Customers.FirstOrDefault(c => c.CustomerId == id); if (cs == null) { return(null); } else { cs = customerDto.ToModel(); db.Entry(cs).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); return(cs.ToDto()); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public void AddCustomer(CustomerDto dto) { var entity = dto.ToModel <Customer>(); entity.AnswerTime = DateTime.Now; CustomerRepository.Insert(entity); }
public async Task <CustomerDto> CreateCustomer(CustomerDto customerDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (customerDto == null) { return(null); } else { db.Customers.Add(customerDto.ToModel()); await db.SaveChangesAsync(); return(customerDto); } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }