public ActionResult SaveFloor(TempFloorPlan model) { var fp = Db.tabTempFloorPlans.Include("TempFloorTables").Where(p => p.FloorPlanId == model.FloorPlanId).Single(); var isFloorActive = Db.tabFloorPlans; int[] lvl = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int flvl; if (isFloorActive.Count() == 0) { flvl = 1; } else { flvl = lvl.Where(p => !isFloorActive.Select(s => s.FLevel).ToList().Contains(p)).FirstOrDefault(); } var floorPlan = new FloorPlan() { CreatedOn = fp.CreatedOn, FloorName = model.FloorName, PhotoPath = fp.PhotoPath, UserId = fp.UserId, FLevel = flvl, IsActive = isFloorActive.Count() == 0 ? true : false, UpdatedBy = User.Identity.GetUserId<long>(), UpdatedOn = DateTime.UtcNow, }; Db.tabFloorPlans.Add(floorPlan); foreach (var item in fp.TempFloorTables) { var floorTable = new FloorTable() { Angle = item.Angle, CreatedOn = item.CreatedOn, FloorPlanId = floorPlan.FloorPlanId, TableDesign = item.TableDesign, MaxCover = item.MaxCover, MinCover = item.MinCover, TableName = item.TableName, TBottom = item.TBottom, TLeft = item.TLeft, TRight = item.TRight, TTop = item.TTop, UpdatedOn = item.UpdatedOn, HtmlId = item.HtmlId, Shape = item.Shape, Size = item.Size, IsTemporary = false }; Db.tabFloorTables.Add(floorTable); //StringBuilder design = new StringBuilder(); //design.Append(item.TableDesign.Substring(0, item.TableDesign.LastIndexOf("<input"))); //design.Append("<input id=\"FloorTableId\" name=\"FloorTableId\" type=\"hidden\" value=\"" + floorTable.FloorTableId + "\"/></div>"); //floorTable.TableDesign = design.ToString(); //Db.Entry(floorTable).State = EntityState.Modified; } Db.SaveChanges(); return RedirectToAction("Index"); }
public ActionResult NewFloorPlan() { var UserId = User.Identity.GetUserId<long>(); var floor_Name = "Temp Floor " + ((Db.tabFloorPlans.Count() != 0) ? Db.tabFloorPlans.Max(p => p.FloorPlanId) : 0); //var floor_Name = "TempFloor" ; if (Session["TempFloorUId"] == null) { this.ManageTempTables(); var model = new TempFloorPlan() { UserId = UserId, Guid = Guid.NewGuid().ToString(), FloorName = floor_Name, CreatedOn = DateTime.UtcNow.ToClientTime() }; Db.tabTempFloorPlans.Add(model); Db.SaveChanges(); Session["TempFloorUId"] = model.Guid; return View(model); } else { var Uid = (string)Session["TempFloorUId"]; var model = Db.tabTempFloorPlans.Include("TempFloorTables").Where(tf => tf.Guid == Uid).SingleOrDefault(); if (model == null) { model = new TempFloorPlan() { UserId = UserId, Guid = Guid.NewGuid().ToString(), FloorName = floor_Name, CreatedOn = DateTime.UtcNow.ToClientTime() }; Db.tabTempFloorPlans.Add(model); Db.SaveChanges(); } if (model.TempFloorTables != null) { foreach (var item in model.TempFloorTables) { FloorTable copyTable = new FloorTable(); CopyHelper.Copy(typeof(TempFloorTable), item, typeof(FloorTable), copyTable); item.TableDesign = this.RenderPartialViewToString("GetFloorItemTemplate", copyTable); copyTable = null; } } Session["TempFloorUId"] = model.Guid; return View(model); } }