public ActionResult Create(PlanViewModel plan) { if (ModelState.IsValid) { var newPlan = new Plan { Created = DateTimeOffset.UtcNow, Updated = DateTimeOffset.UtcNow, Name = plan.Name.Trim(), Area = plan.Area, Price = plan.Price }; context.Plans.Add(newPlan); context.SaveChanges(); plan.ID = newPlan.ID; if (plan.PreviewImageFile != null || plan.ModelFilePath != null) { string root = ConfigurationManager.AppSettings["UserDataRoot"]; root = Path.Combine(root, "plans", newPlan.ID.ToString()); IStorage storage = this.GetStorage(Server.MapPath(root)); storage.EnsureRootExist(); // Preview string fileName = newPlan.Updated.UtcTicks.ToString(); if (plan.PreviewImageFile != null && plan.PreviewImageFile.ContentLength > 0 || plan.ModelFile != null && plan.ModelFile.ContentLength > 0) { string ext = plan.PreviewImageFile.InputStream.GetFileExtension(); ext = ext == null ? null : ext.ToLower(); storage.Save(plan.PreviewImageFile.InputStream, fileName + ext); newPlan.PreviewImageFilePath = Path.Combine(root, fileName + ext); } if (plan.ModelFile != null && plan.ModelFile.ContentLength > 0) { string ext = plan.ModelFile.InputStream.GetFileExtension(); ext = ext == null ? null : ext.ToLower(); storage.Save(plan.ModelFile.InputStream, fileName + ext); newPlan.ModelFilePath = Path.Combine(root, fileName + ext); } context.Entry <Plan>(newPlan).State = EntityState.Modified; context.SaveChanges(); } return(RedirectToAction("Edit", new { ID = newPlan.ID })); } return(View(plan)); }
public ActionResult Edit(UserProfile userprofile) { if (ModelState.IsValid) { context.Entry(userprofile).State = EntityState.Modified; context.SaveChanges(); return(RedirectToAction("Index")); } return(View(userprofile)); }
public ActionResult Edit(FloorTemplate floor) { if (ModelState.IsValid) { context.Entry(floor).State = EntityState.Modified; context.SaveChanges(); return(RedirectToAction("Index")); } return(View(floor)); }
public ActionResult Edit(ShiftRight.Heim.Models.Attribute attr) { using (var dtx = new HeimContext()) { if (this.ModelState.IsValid) { dtx.Entry <ShiftRight.Heim.Models.Attribute>(attr).State = System.Data.Entity.EntityState.Modified; dtx.SaveChanges(); } return(RedirectToAction("Edit", "Plans", new { id = attr.PlanID })); } }
public ActionResult Edit(AssetViewModel asset) { using (var dtx = new HeimContext()) { asset.Updated = DateTimeOffset.UtcNow; SaveAssetFiles(dtx, asset); dtx.Entry <Asset>(asset).State = EntityState.Modified; dtx.SaveChanges(); return(View(asset)); } }
public ActionResult Create([Bind(Exclude = "ID")] AssetViewModel mat) { using (var dtx = new HeimContext()) { if (ModelState.IsValid) { mat.Created = DateTimeOffset.UtcNow; mat.Updated = mat.Created; dtx.Assets.Add(mat as Asset); dtx.SaveChanges(); SaveAssetFiles(dtx, mat); dtx.Entry <Asset>(mat as Asset).State = EntityState.Modified; dtx.SaveChanges(); } return(View(mat)); } }