public static UserProfile GetCurrentUser(this Controller controller) { if (controller.User != null && controller.User.Identity.IsAuthenticated) { UserProfile user = controller.Session["current_user"] as UserProfile; if (user == null) { using (var dtx = new HeimContext()) { user = dtx.UserProfiles.SingleOrDefault(u => u.Username == controller.User.Identity.Name); if (user != null) { controller.Session["current_user"] = user; return(user); } controller.Response.Cookies.Clear(); HttpCookie c = new HttpCookie("login"); c.Expires = DateTime.Now.AddDays(-1); controller.Response.Cookies.Add(c); WebMatrix.WebData.WebSecurity.Logout(); FormsAuthentication.SignOut(); controller.Session.Clear(); controller.Session.Abandon(); controller.Response.Redirect("Home/Index", true); } } return(user); } return(null); }
public ActionResult Home() { using (var dtx = new HeimContext()) { var user = this.GetCurrentUser(); var query = from project in dtx.Projects where project.OwnerID == user.ID orderby project.Updated descending select new ProjectViewModel { ID = project.ID, Created = project.Created, Name = project.Name, //PreviewImage = project. Plan = new PlanViewModel { Area = project.PlanTemplate.Area, Name = project.PlanTemplate.Name, PreviewImage = project.PlanTemplate.PreviewImageFilePath } }; var list = query.ToList(); list.ForEach(x => x.PreviewImage = x.Plan.PreviewImage); return(View( new ProjectHomeViewModel { Projects = list })); } }
// // GET: /Floors/Edit/5 public ActionResult Edit(int id) { using (var dtx = new HeimContext()) { var query = from floor in dtx.Floors where floor.ID == id select new FloorViewModel { ID = floor.ID, FloorNumber = floor.FloorNumber, Plan = new PlanViewModel { ID = floor.PlanID, Name = floor.Plan.Name }, Variants = floor.Variants.Select(v => new FloorVariantViewModel { ID = v.ID, FloorNumber = v.Floor.FloorNumber, Name = v.Name, Created = v.Created, Updated = v.Updated }) }; var f = query.Single(); return(View(f)); } }
public ActionResult Delete(int id) { using (var dtx = new HeimContext()) { Project project = dtx.Projects.Single(x => x.ID == id); return(View(project)); } }
public ActionResult Json(int?projectId = null) { Project cp = null; if (projectId != null) { using (var dtx = new HeimContext()) { cp = dtx.Projects.Find(projectId); } } else { cp = CurrentProject; } if (cp == null) { Response.StatusCode = (int)HttpStatusCode.NotFound; return(Json(new { Message = "Project not found" }, JsonRequestBehavior.AllowGet)); } var result = new { cp.ID, cp.Name, cp.Created, cp.Updated, cp.Data }; return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult Customize(int planId) { using (var dtx = new HeimContext()) { var plan = dtx.Plans.Include("Floors").Include("Attributes").Include("Floors.Variants").Single(p => p.ID == planId); if (plan == null) { return(RedirectToAction("New")); } ViewBag.Title = plan.Name; var vm = new CustomizeProjectViewModel { Name = plan.Name, PreviewImage = plan.PreviewImageFilePath, Plan = new PlanViewModel { ID = plan.ID, Name = plan.Name, PreviewImage = plan.PreviewImageFilePath, Floors = plan.Floors.Select(fl => new FloorViewModel { ID = fl.ID, FloorNumber = fl.FloorNumber, Variants = fl.Variants.Select(vr => new FloorVariantViewModel { ID = vr.ID, Name = vr.Name, IsDefault = false, PlanPreviewImageFilePath = vr.PlanPreviewImageFilePath }).ToList() }).ToList(), }, Attributes = plan.Attributes.ToList() }; foreach (var item in vm.Plan.Floors) { if (item.Variants.Count() > 0) { foreach (var vr in item.Variants) { vr.IsDefault = true; item.PlanPreviewImage = vr.PlanPreviewImageFilePath; break; } } } //vm.Attributes.Add(new ShiftRight.Heim.Models.Attribute { // ID = 0, // Name = "พื้นที่ใช้สอย", // Unit = //}); return(View(vm)); } // end using }
public ActionResult Edit(PlanViewModel plan) { using (var dtx = new HeimContext()) { var planModel = dtx.Plans.Include("Floors").Single(s => s.ID == plan.ID); //plan.Attributes = planModel.Attributes.ToList(); if (ModelState.IsValid) { planModel.Updated = DateTimeOffset.UtcNow; planModel.Name = plan.Name.Trim(); planModel.Area = plan.Area; planModel.Price = plan.Price; IStorage storage = null; string root = null; // prepare storage if (plan.PreviewImageFile != null && plan.PreviewImageFile.ContentLength > 0 || plan.ModelFile != null && plan.ModelFile.ContentLength > 0) { string fileName = planModel.Updated.UtcTicks.ToString(); root = ConfigurationManager.AppSettings["UserDataRoot"]; root = Path.Combine(root, "plans", plan.ID.ToString()); storage = this.GetStorage(Server.MapPath(root)); storage.EnsureRootExist(); if (plan.PreviewImageFile != null && plan.PreviewImageFile.ContentLength > 0) { string ext = plan.PreviewImageFile.InputStream.GetFileExtension(); ext = ext == null ? null : ext.ToLower(); storage.Save(plan.PreviewImageFile.InputStream, fileName + ext); planModel.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); planModel.ModelFilePath = Path.Combine(root, fileName + ext); } } context.Entry <Plan>(planModel).State = EntityState.Modified; context.SaveChanges(); if (plan.PreviewImageFile == null) { return(RedirectToAction("Index")); } } return(RedirectToAction("Edit", new { id = plan.ID })); } }
public ActionResult Edit(int id) { using (var dtx = new HeimContext()) { var query = from v in dtx.FloorVariants where v.ID == id select new FloorVariantViewModel { ID = v.ID, FloorID = v.FloorID, PlanID = v.Floor.PlanID, FloorNumber = v.Floor.FloorNumber, Created = v.Created, Updated = v.Updated, Name = v.Name, PlanPreviewImageFilePath = v.PlanPreviewImageFilePath, ModelFilePath = v.ModelFilePath }; var variant = query.Single(); if (!String.IsNullOrEmpty(variant.ModelFilePath)) { string modelFilePath = Server.MapPath(variant.ModelFilePath); if (System.IO.File.Exists(modelFilePath)) { variant.ModelFileSize = Math.Floor(new FileInfo(modelFilePath).Length / 1024.0); } } return(View(variant)); } }
public ActionResult Delete(int id) { using (var dtx = new HeimContext()) { ShiftRight.Heim.Models.Attribute attr = dtx.Attributes.Single(x => x.ID == id); return(View(attr)); } }
public ActionResult New(string search) { ViewBag.Title = "Select house plan"; using (var dtx = new HeimContext()) { if (!String.IsNullOrWhiteSpace(search)) { search = search.Trim().ToLower(); } else { search = null; } var query = from item in dtx.Plans where (search == null || item.Name.ToLower().Contains(search)) && item.Floors.Count() > 0 orderby item.Name select new PlanViewModel { ID = item.ID, Name = item.Name, PreviewImage = item.PreviewImageFilePath, Area = item.Area }; NewProjectViewModel vm = new NewProjectViewModel { Search = search, Plans = query.ToList() }; return(View(vm)); } }
//public ActionResult Index() { // return View(); //} public ActionResult Edit(int id) { using (var dtx = new HeimContext()) { var attr = dtx.Attributes.Find(id); return(View(attr)); } }
public ActionResult Delete(int id) { using (var dtx = new HeimContext()) { var asset = dtx.Assets.Find(id); return(View(asset)); } }
public ActionResult Edit(FloorVariantViewModel variant) { DateTimeOffset updated = DateTimeOffset.UtcNow; using (var dtx = new HeimContext()) { if (ModelState.IsValid) { var fv = dtx.FloorVariants.Single(v => v.ID == variant.ID); fv.Name = variant.Name.Trim(); fv.Updated = updated; IStorage storage = null; string root = null; // prepare storage if (variant.PlanImageFile != null || variant.ModelFile != null) { root = ConfigurationManager.AppSettings["UserDataRoot"]; root = Path.Combine(root, "plans", variant.PlanID.ToString(), "variants", variant.ID.ToString()); storage = this.GetStorage(Server.MapPath(root)); storage.EnsureRootExist(); } string ext = ""; if (variant.PlanImageFile != null) { ext = variant.PlanImageFile.InputStream.GetFileExtension(); ext = ext == null? null : ext.ToLower(); fv.PlanPreviewImageFilePath = Path.Combine(root, fv.Updated.Ticks.ToString() + ext); storage.Save(variant.PlanImageFile.InputStream, fv.Updated.Ticks.ToString() + ext); } if (variant.ModelFile != null) { ext = variant.ModelFile.InputStream.GetFileExtension(); ext = ext == null ? null : ext.ToLower(); // add allowed file extensions here if (ext == ".zip") { fv.ModelFilePath = Path.Combine(root, fv.Updated.Ticks.ToString() + ext); storage.Save(variant.ModelFile.InputStream, fv.Updated.Ticks.ToString() + ext); } } dtx.SaveChanges(); return(RedirectToAction("Edit", new { id = variant.ID })); } } return(View(variant)); }
public ActionResult DeleteConfirmed(int id) { using (var dtx = new HeimContext()) { ShiftRight.Heim.Models.Attribute attr = dtx.Attributes.Single(x => x.ID == id); dtx.Attributes.Remove(attr); dtx.SaveChanges(); return(RedirectToAction("Edit", "Plans", new { id = attr.PlanID })); } }
public ActionResult DeleteConfirmed(int id) { using (var dtx = new HeimContext()) { Asset asset = dtx.Assets.Single(x => x.ID == id); dtx.Assets.Remove(asset); dtx.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult Delete(int id) { using (var dtx = new HeimContext()) { var variant = dtx.FloorVariants.Single(v => v.ID == id); dtx.FloorVariants.Remove(variant); dtx.SaveChanges(); return(RedirectToAction("Edit", "Floors", new { id = variant.FloorID })); } }
public ActionResult Index() { using (var dtx = new HeimContext()) { var query = from mat in dtx.Assets orderby mat.AssetType, mat.Name group mat by mat.AssetType into matgroup select matgroup; return(View(query.ToList())); } }
public ActionResult AddAttribute(ShiftRight.Heim.Models.Attribute attr) { using (var dtx = new HeimContext()) { if (ModelState.IsValid) { dtx.Attributes.Add(attr); dtx.SaveChanges(); } return(RedirectToAction("Edit", new { id = attr.PlanID })); } }
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 Exterior() { ViewBag.BodyCssClass = "design-exterior"; if (CurrentProject == null) { return(RedirectToAction("Home", "Projects")); } using (var dtx = new HeimContext()) { Project project = CurrentProject; var query = from asset in dtx.Assets orderby asset.Name select asset; var groups = from asset in query.ToList() group new AssetViewModel { ID = asset.ID, Name = asset.Name, Mapping = asset.Mapping, Created = asset.Created, Updated = asset.Updated, PreviewFilePath = asset.PreviewFilePath, AssetType = asset.AssetType, AssetFilePath = asset.AssetFilePath, } by asset.AssetType into assetGroup select assetGroup; groups = groups.ToList(); foreach (var group in groups) { foreach (var item in group) { item.Selected = true; break; } } var vm = new ExteriorViewModel { Project = CurrentProject, ProjectName = project.Name, ProjectID = project.ID, Assets = groups, Floors = project.PlanTemplate.Floors }; return(View(vm)); } }
public ActionResult CreateBlank(int planId) { using (var dtx = new HeimContext()) { int?floorNumber = dtx.Floors.Where(f => f.PlanID == planId).Max(f => (int?)f.FloorNumber); var floor = new FloorTemplate { PlanID = planId, FloorNumber = floorNumber.HasValue? +floorNumber.Value + 1: 1 }; dtx.Floors.Add(floor); dtx.SaveChanges(); return(RedirectToAction("Edit", new { id = floor.ID })); } }
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)); } }
// // GET: /Floors/Delete/5 public ActionResult Delete(int id) { using (var dtx = new HeimContext()) { var query = from fl in dtx.Floors where fl.ID == id select new FloorViewModel { ID = fl.ID, FloorNumber = fl.FloorNumber, Plan = new PlanViewModel { ID = fl.PlanID, Name = fl.Plan.Name } }; return(View(query.Single())); } }
public ActionResult Index() { using (var dtx = new HeimContext()) { var query = from p in dtx.Projects orderby p.Created descending select new ProjectViewModel { ID = p.ID, Created = p.Created, Name = p.Name, Owner = p.Owner }; return(View(new ProjectIndexViewModel { Projects = query.ToList() })); } }
public ActionResult Edit(int id) { using (var dtx = new HeimContext()) { var asset = dtx.Assets.Find(id); return(View(new AssetViewModel { ID = asset.ID, Name = asset.Name, Mapping = asset.Mapping, Created = asset.Created, Updated = asset.Updated, PreviewFilePath = asset.PreviewFilePath, AssetType = asset.AssetType, AssetFilePath = asset.AssetFilePath, })); } }
public SimpleMembershipInitializer() { Database.SetInitializer <HeimContext>(null); try { using (var context = new HeimContext()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } WebSecurity.InitializeDatabaseConnection("DefaultConnection", "Users", "ID", "UserName", autoCreateTables: true); } catch (Exception ex) { throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); } }
public ActionResult CreateBlank(int floorId) { using (var dtx = new HeimContext()) { var floor = dtx.Floors.Find(floorId); int variantCount = dtx.FloorVariants.Where(fv => fv.FloorID == floorId).Count(); var variant = new FloorVariant { Created = DateTimeOffset.UtcNow, Updated = DateTimeOffset.UtcNow, Name = "Variant " + (variantCount + 1), FloorID = floorId, }; floor.Variants.Add(variant); dtx.SaveChanges(); return(RedirectToAction("Edit", new { id = variant.ID, create = true })); } }
private void SaveAssetFiles(HeimContext dtx, AssetViewModel mat) { // Save Material file and Preview file IStorage storage = null; string root = null; // prepare storage if (mat.PreviewImageFile != null || mat.AssetFile != null) { root = ConfigurationManager.AppSettings["UserDataRoot"]; root = Path.Combine(root, "assets", mat.ID.ToString()); storage = this.GetStorage(Server.MapPath(root)); storage.EnsureRootExist(); } string ext = ""; if (mat.PreviewImageFile != null) { ext = mat.PreviewImageFile.InputStream.GetFileExtension(); ext = ext == null ? null : ext.ToLower(); if (mat != null) { mat.PreviewFilePath = Path.Combine(root, "pre_" + mat.Updated.Ticks.ToString() + ext).Replace('\\', '/'); storage.Save(mat.PreviewImageFile.InputStream, "pre_" + mat.Updated.Ticks.ToString() + ext); } } if (mat.AssetFile != null) { ext = mat.AssetFile.InputStream.GetFileExtension(); ext = ext == null ? null : ext.ToLower(); if (ext != null) { mat.AssetFilePath = Path.Combine(root, mat.Updated.Ticks.ToString() + ext).Replace('\\', '/'); storage.Save(mat.AssetFile.InputStream, mat.Updated.Ticks.ToString() + ext); } } }
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)); } }