public async Task <PackageDto> UpdatePackage(int id, PackageDto packageDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (id != packageDto.PackageId) { return(null); } else { Package p = db.Packages.FirstOrDefault(c => c.PackageId == id); if (p == null) { return(null); } else { p = packageDto.ToModel(); db.Entry(p).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); return(p.ToDto()); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <LineDto> CreateLine(LineDto lineDto, SelectedNumberDto selectedNumberDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (lineDto == null) { return(null); } else { lineDto.SelectedNumbers = selectedNumberDto; db.Lines.Add(lineDto.ToModel()); await db.SaveChangesAsync(); return(lineDto); } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <PackageDto> DeletePackage(int id) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { Package package = await db.Packages.FindAsync(id); if (package == null) { return(null); } else { db.Packages.Remove(package); await db.SaveChangesAsync(); return(package.ToDto()); } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <PackageDto> CreatePackage(PackageDto packageDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (packageDto == null) { return(null); } else { db.Packages.Add(packageDto.ToModel()); await db.SaveChangesAsync(); return(packageDto); } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <bool> DeleteLine(int lineId) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { var line = db.Lines.FirstOrDefault(l => l.LineId == lineId); if (line != null) { var selectedNumbers = db.SelectedNumbers.FirstOrDefault(l => l.Id == line.LineId); db.SelectedNumbers.Remove(selectedNumbers); db.Lines.Remove(line); await db.SaveChangesAsync(); return(true); } return(false); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(false); } } }
public async Task <PackageDto> CreatePackage(PackageDto package, PackageIncludesDto packageIncludes) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (package != null) { PackageEntity entity = new PackageEntity() { PackageName = package.PackageName, PackageTotalPrice = package.PackageTotalPrice, }; db.PackageIncludes.Add(packageIncludes.ToModel()); await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <LineDto> UpdateLine(LineDto line, string clientId) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (line != null) { if (line.ClientId == clientId) { LineEntity entity = line.ToModel(); entity.LineId = line.LineId; db.Lines.Attach(entity); foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames) { if (propName != "LineId") { db.Entry(entity).Property(propName).IsModified = true; } } await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <LineDto> UpdateLine(int id, LineDto lineDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (lineDto != null && id != 0 && CheckIfLineNumberAlreadyExist(lineDto.Number)) { lineDto.LineId = id; Line entity = lineDto.ToModel(); db.Lines.Attach(entity); foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames) { if (propName != nameof(entity.LineId)) { db.Entry(entity).Property(propName).IsModified = true; } } await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <SelectedNumberDto> UpdateSelectedNumber(int id, SelectedNumberDto selectedNumberDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { if (id != selectedNumberDto.SelectedNumberId) { return(null); } else { var sn = db.SelectedNumbers.FirstOrDefault(s => s.SelectedNumberId == id); if (sn == null) { return(null); } else { SelectedNumbers selectedNumber = selectedNumberDto.ToModel(); db.Entry(selectedNumber).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); return(sn.ToDto()); } } } }
public async Task <PackageDto> UpdatePackage(PackageDto package, int lineId, string clientId) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (package != null) { if (CheckIfPackageBelongsToClient(package, lineId, clientId)) { PackageEntity entity = package.ToModel(); entity.PackageId = package.PackageId; db.Packages.Attach(entity); foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames) { if (propName != "PackageId") { db.Entry(entity).Property(propName).IsModified = true; } } await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <SelectedNumbersDto> UpdateSelectedNumber(SelectedNumbersDto number) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (number != null) { SelectedNumbersEntity entity = number.ToModel(); entity.Id = number.Id; db.SelectedNumbers.Attach(entity); foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames) { if (propName != "Id") { db.Entry(entity).Property(propName).IsModified = true; } } await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <ClientDto> UpdateClient(ClientDto client, string clientId) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (client != null && clientId != null) { client.ClientId = clientId; ClientEntity entity = client.ToModel(); db.Clients.Attach(entity); foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames) { if (propName != nameof(entity.ClientId)) { db.Entry(entity).Property(propName).IsModified = true; } } await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <CallsDto> UpdateCall(CallsDto call) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (call != null) { CallsEntity entity = call.ToModel(); entity.CallId = call.CallId; db.Calls.Attach(entity); foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames) { if (propName != "CallId") { db.Entry(entity).Property(propName).IsModified = true; } } await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } 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); } } }
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 <SMSDto> UpdateSMS(int id, SMSDto smsDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { if (id != smsDto.SMSId) { return(null); } else { var sms = db.SMSs.FirstOrDefault(s => s.SMSId == id); if (sms == null) { return(null); } else { SMS sMS = smsDto.ToModel(); db.Entry(sMS).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); return(sms.ToDto()); } } } }
public async Task <CustomerTypeDto> DeleteCustomerType(int id) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { CustomerType customerType = await db.CustomerTypes.FindAsync(id); if (customerType == null) { return(null); } else { db.CustomerTypes.Remove(customerType); await db.SaveChangesAsync(); return(customerType.ToDto()); } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <SMSDto> UpdateSMS(SMSDto sms) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (sms != null) { SMSEntity entity = sms.ToModel(); entity.SMSId = sms.SMSId; db.SMS.Attach(entity); foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames) { if (propName != "SMSId") { db.Entry(entity).Property(propName).IsModified = true; } } await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <PaymentDto> UpdatePayment(PaymentDto payment) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (payment != null) { PaymentEntity entity = payment.ToModel(); entity.PaymentId = payment.PaymentId; db.Payment.Attach(entity); foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames) { if (propName != "PaymentId") { db.Entry(entity).Property(propName).IsModified = true; } } await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <PaymentDto> UpdatePayment(int id, PaymentDto paymentDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { if (id != paymentDto.CustomerId) { return(null); } else { var py = db.Payments.FirstOrDefault(p => p.PaymentId == id); if (py == null) { return(null); } else { Payment payment = paymentDto.ToModel(); db.Entry(payment).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); return(py.ToDto()); } } } }
public async Task <PaymentDto> CreatePayment(PaymentDto paymentDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { if (paymentDto == null) { return(null); } else { db.Payments.Add(paymentDto.ToModel()); await db.SaveChangesAsync(); return(paymentDto); } } }
public async Task <SelectedNumberDto> CreateSelectedNumber(SelectedNumberDto selectedNumberDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { if (selectedNumberDto == null) { return(null); } else { db.SelectedNumbers.Add(selectedNumberDto.ToModel()); await db.SaveChangesAsync(); return(selectedNumberDto); } } }
public async Task <SMSDto> CreateSMS(SMSDto smsDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { if (smsDto == null) { return(null); } else { db.SMSs.Add(smsDto.ToModel()); await db.SaveChangesAsync(); return(smsDto); } } }
public async Task <SMSDto> DeleteSMS(int id) { using (CellularCompanyContext db = new CellularCompanyContext()) { SMS sMS = await db.SMSs.FindAsync(id); if (sMS == null) { return(null); } else { db.SMSs.Remove(sMS); await db.SaveChangesAsync(); return(sMS.ToDto()); } } }
public async Task <PaymentDto> DeletePayment(int id) { using (CellularCompanyContext db = new CellularCompanyContext()) { Payment payment = await db.Payments.FindAsync(id); if (payment == null) { return(null); } else { db.Payments.Remove(payment); await db.SaveChangesAsync(); return(payment.ToDto()); } } }
public async Task <SelectedNumberDto> DeleteSelectedNumber(int id) { using (CellularCompanyContext db = new CellularCompanyContext()) { SelectedNumbers selectedNumber = await db.SelectedNumbers.FindAsync(id); if (selectedNumber == null) { return(null); } else { db.SelectedNumbers.Remove(selectedNumber); await db.SaveChangesAsync(); return(selectedNumber.ToDto()); } } }
public async Task <bool> DeleteClientType(int id) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { var clientEntity = db.ClientType.FirstOrDefault(c => c.ClientTypeId == id); if (clientEntity != null) { db.ClientType.Remove(clientEntity); await db.SaveChangesAsync(); return(true); } return(false); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(false); } } }
public async Task <List <ClientTypeDto> > AddOrUpdateClientType() { using (CellularCompanyContext db = new CellularCompanyContext()) { try { List <ClientTypeEntity> list = GetClientTypes().Select(c => c.ToModel()).ToList(); foreach (var item in list) { db.ClientType.AddOrUpdate(t => t.TypeName, item); } await db.SaveChangesAsync(); List <ClientTypeDto> clientTypes = db.ClientType.ToList().Select(c => c.ToDto()).ToList(); return(clientTypes); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <bool> DeleteLine(string number) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { var line = db.Lines.FirstOrDefault(l => l.Number == number); if (line != null) { db.Lines.Remove(line); await db.SaveChangesAsync(); return(true); } return(false); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(false); } } }
public async Task <LineDto> CreateLine(LineDto line) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (line != null) { LineEntity entity = line.ToModel(); db.Lines.Add(entity); await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }