public Package Create(PackagePostModel packagePostModel) { Package toAdd = PackagePostModel.ToPackage(packagePostModel); context.Packages.Add(toAdd); context.SaveChanges(); return(toAdd); }
public PackagePostModel AddPackage(PackagePostModel packagePostModel) { var package = PackagePostModel.ToPackage(packagePostModel); if (package == null) { return(null); } context.Packages.Add(package); context.SaveChanges(); return(packagePostModel); }
public Package Upsert(int id, PackagePostModel packagePostModel) { Package toAdd = PackagePostModel.ToPackage(packagePostModel); var existing = context.UserRole.AsNoTracking().FirstOrDefault(f => f.Id == id); if (existing == null) { context. Packages.Add(toAdd); context.SaveChanges(); return(toAdd); } toAdd.Id = id; context.Packages.Update(toAdd); context.SaveChanges(); return(toAdd); }
public Package UpsertPackage(int id, PackagePostModel packagePostModel) { var existingPackage = context.Packages.AsNoTracking().FirstOrDefault(c => c.Id == id); if (existingPackage == null) { var package = PackagePostModel.ToPackage(packagePostModel); context.Packages.Add(package); context.SaveChanges(); return(package); } var resPackage = PackagePostModel.ToPackage(packagePostModel); resPackage.Id = id; context.Packages.Update(resPackage); context.SaveChanges(); return(resPackage); }