public async Task <CustomerTypeDto> UpdateCustomerType(int id, CustomerTypeDto customerTypeDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (id != customerTypeDto.CustomerTypeId) { return(null); } else { CustomerType ct = db.CustomerTypes.FirstOrDefault(c => c.CustomerTypeId == id); if (ct == null) { return(null); } else { ct = customerTypeDto.ToModel(); db.Entry(ct).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); return(ct.ToDto()); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <CustomerTypeDto> CreateCustomerType(CustomerTypeDto customerTypeDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (customerTypeDto == null) { return(null); } else { db.CustomerTypes.Add(customerTypeDto.ToModel()); await db.SaveChangesAsync(); return(customerTypeDto); } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }