Exemplo n.º 1
0
 internal static Package ToDTO(this PackageDb packageDb)
 {
     return(new Package
     {
         Id = packageDb.Id,
         //Line = packageDb.Line.ToDTO(),
         PackageTotalPrice = packageDb.PackageTotalPrice,
         PackageName = packageDb.PackageName,
         PackageIncludes = packageDb.PackageIncludes.ToDTO(),
         //LineId = packageDb.LineId,
         PackageIncludesId = packageDb.PackageIncludesId
     });
 }
 public bool UpdatePackage(Package package)
 {
     using (var db = new CellDbContext())
     {
         try
         {
             PackageDb packageToUpdate = db.Packages.SingleOrDefault(p => p.Id == package.Id);
             db.Entry(package).State = System.Data.Entity.EntityState.Modified;
             packageToUpdate         = package.FromDTO();
             db.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             return(false);
         }
     }
 }
 public Package AddPackage(Package package)
 {
     using (var db = new CellDbContext())
     {
         try
         {
             PackageDb newPackage;
             PackageDb packageDb = package.FromDTO();
             newPackage = db.Packages.Add(packageDb);
             db.Entry(package).State = System.Data.Entity.EntityState.Added;
             db.SaveChanges();
             return(newPackage.ToDTO());
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
             return(null);
         }
     }
 }