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 <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 <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 <PackageDto> CreatePackage(PackageDto package) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (package != null) { PackageEntity entity = package.ToModel(); db.Packages.Add(entity); await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <PackageModel> GetPackage(int lineId) { PackageDto a = await invoice.GetLinePackageAsync(lineId); return(a.ToModel()); }