public ActionResult SaveCustomize(ProjectViewModel model) { using(var dtx = new HeimContext()) { var user = dtx.UserProfiles.Single(u => u.Username == User.Identity.Name); var selectedVariants = model.Floors.Select(f => f.ID).ToArray(); var variants = dtx.FloorVariants .Where(fv => selectedVariants.Contains(fv.ID)) .Select(fv => new { fv.Floor.FloorNumber, ModelName = "fl_" + SqlFunctions.StringConvert((decimal?)fv.Floor.FloorNumber), fv.ModelFilePath, fv.Name, fv.ID }).ToList(); var project = new Project(); model.ModelFile = dtx.Plans.Where(p => p.ID == model.Plan.ID).Select(p => p.ModelFilePath).FirstOrDefault(); model.ModelFile = String.IsNullOrEmpty(model.ModelFile) ? null : VirtualPathUtility.ToAbsolute(model.ModelFile); project.ID = 0; project.OwnerID = user.ID; project.Created = DateTimeOffset.UtcNow; project.Updated = DateTimeOffset.UtcNow; project.IsDeleted = false; project.PlanTemplateID = model.Plan.ID; project.Name = model.Name.Trim(); project.Data = System.Web.Helpers.Json.Encode(new { ModelFilePath = model.ModelFile, Floors = variants.Select(fv => new { fv.FloorNumber, ModelFilePath = String.IsNullOrEmpty(fv.ModelFilePath)? null: VirtualPathUtility.ToAbsolute(fv.ModelFilePath), fv.Name, fv.ID }).ToArray() }); //project.Floors //project.Data = ; dtx.Projects.Add(project); dtx.SaveChanges(); return Json(project); } }
public ActionResult Save(Project project) { using(var dtx = new HeimContext()) { var p = dtx.Projects.Find(project.ID); if(p != null) { p.Name = project.Name; p.Data = project.Data; p.Updated = DateTimeOffset.UtcNow; dtx.SaveChanges(); return Json(p); } else { throw new Exception("Project not found"); } } }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { if(CurrentProject == null && Request != null) { var cookie = Request.Cookies["current_project_id"]; if(cookie != null) { int id = int.Parse(cookie.Value); using(var dtx = new HeimContext()) { var project = dtx.Projects.Include("PlanTemplate.Floors").SingleOrDefault(p => p.ID == id); if(project != null) { CurrentProject = project; Response.SetCookie(new HttpCookie("current_project_id", id.ToString())); } } } } base.OnActionExecuting(filterContext); }
public ActionResult Open(int id) { using(var dtx = new HeimContext()) { var project = dtx.Projects.Include("PlanTemplate.Floors").SingleOrDefault(p => p.ID == id); if(project != null) { CurrentProject = project; Response.SetCookie(new HttpCookie("current_project_id", id.ToString())); var cookie = Request.Cookies["current_project_id"]; return RedirectToAction("Exterior"); } else { return RedirectToAction("Home", "Projects", null); } } }