public async Task <PackageIncludesDto> UpdatePackageInclude(PackageIncludesDto packageIncludes) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (packageIncludes != null) { PackageIncludesEntity entity = packageIncludes.ToModel(); entity.Id = packageIncludes.Id; db.PackageIncludes.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 <PackageIncludesDto> CreatePackageInclude(PackageIncludesDto package) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (package != null) { PackageIncludesEntity entity = package.ToModel(); db.PackageIncludes.Add(entity); await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }