Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        public ActionResult Create(UserProfile userprofile)
        {
            if (ModelState.IsValid)
            {
                context.UserProfiles.Add(userprofile);
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userprofile));
        }
Exemplo n.º 3
0
        public ActionResult Create(FloorTemplate floor)
        {
            if (ModelState.IsValid)
            {
                context.Floors.Add(floor);
                context.SaveChanges();

                return(RedirectToAction("Edit", new { id = floor.ID }));
            }

            return(View(floor));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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"));
     }
 }
Exemplo n.º 6
0
 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 }));
     }
 }
Exemplo n.º 7
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));
            }
        }
Exemplo n.º 8
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 }));
            }
        }
Exemplo n.º 9
0
        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 }));
            }
        }
Exemplo n.º 10
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 }));
            }
        }
Exemplo n.º 11
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));
            }
        }
Exemplo n.º 12
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 }));
            }
        }
Exemplo n.º 13
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));
            }
        }
Exemplo n.º 14
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 }));
            }
        }
Exemplo n.º 15
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");
                }
            }
        }
Exemplo n.º 16
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));
        }