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});
            }
        }
示例#2
0
        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 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 });
            }
        }
示例#4
0
        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 });
            }
        }
示例#5
0
        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);
            }
        }
示例#6
0
        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 });
            }
        }
示例#7
0
        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 });
            }
        }
示例#8
0
        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 });
            }
        }
示例#9
0
        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);
            }
        }
示例#10
0
        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");
                }
            }
        }
示例#11
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if(User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) {
                return RedirectToAction("Manage");
            }

            if(ModelState.IsValid) {
                // Insert a new user into the database
                using(HeimContext db = new HeimContext()) {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.Username.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if(user == null) {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile { Username = model.UserName });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return RedirectToLocal(returnUrl);
                    } else {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
示例#12
0
        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);
            }
        }
示例#13
0
        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);
        }