Пример #1
0
        public ActionResult Details(int id, GameMapVariant model)
        {
            var variant = GameMapService.GetVariant(id);

            variant.Title            = model.Title;
            variant.ShortDescription = model.ShortDescription;
            variant.Description      = model.Description;
            variant.MinPlayers       = model.MinPlayers;
            variant.MaxPlayers       = model.MaxPlayers;
            variant.IsStaffPick      = model.IsStaffPick;
            if (ModelState.IsValid)
            {
                string path = System.IO.Path.Combine(Server.MapPath("~/Content/Files/Forge/"), variant.File.FileName);
                using (FileStream stream = System.IO.File.Open(path, FileMode.Open))
                {
                    VariantLib.ForgeVariant forge = new VariantLib.ForgeVariant(stream);

                    forge.VariantDescription = variant.ShortDescription;
                    forge.VariantName        = variant.Title;
                    forge.Save();
                }

                GameMapService.Save();

                this.SetAlert(string.Format("The variant '{0}' has been updated.", variant.Title), AlertType.Success);
                return(RedirectToAction("Index"));
            }
            return(View(variant));
        }
Пример #2
0
        public ActionResult Details(int id, GameMapVariant model)
        {
            var variant = GameMapService.GetVariant(id);
            variant.Title = model.Title;
            variant.ShortDescription = model.ShortDescription;
            variant.Description = model.Description;
            variant.MinPlayers = model.MinPlayers;
            variant.MaxPlayers = model.MaxPlayers;
            variant.IsStaffPick = model.IsStaffPick;
            if (ModelState.IsValid)
            {
                string path = System.IO.Path.Combine(Server.MapPath("~/Content/Files/Forge/"), variant.File.FileName);
                using (FileStream stream = System.IO.File.Open(path, FileMode.Open))
                {
                    VariantLib.ForgeVariant forge = new VariantLib.ForgeVariant(stream);

                    forge.VariantDescription = variant.ShortDescription;
                    forge.VariantName = variant.Title;
                    forge.Save();
                }

                GameMapService.Save();

                this.SetAlert(string.Format("The variant '{0}' has been updated.", variant.Title), AlertType.Success);
                return RedirectToAction("Index");
            }
            return View(variant);
        }
Пример #3
0
        public ActionResult Edit(int id, Models.GameMapVariant model)
        {
            if (ModelState.IsValid)
            {
                var variant = GameMapService.GetVariant(id);

                if (!(variant.AuthorId == User.Identity.GetUserId <int>() || User.IsInRole("Mod")))
                {
                    return(new HttpUnauthorizedResult());
                }

                variant.Title            = model.Title;
                variant.Description      = model.Description;
                variant.ShortDescription = model.ShortDescription;
                variant.MinPlayers       = model.MinPlayers;
                variant.MaxPlayers       = model.MaxPlayers;

                string path = System.IO.Path.Combine(Server.MapPath("~/Content/Files/Forge/"), variant.File.FileName);
                using (FileStream stream = System.IO.File.Open(path, FileMode.Open))
                {
                    VariantLib.ForgeVariant forge = new VariantLib.ForgeVariant(stream);

                    forge.VariantDescription = variant.ShortDescription;
                    forge.VariantName        = variant.Title;
                    forge.Save();
                }

                if (User.IsInRole("Mod"))
                {
                    variant.IsStaffPick = model.IsStaffPick;
                }

                GameMapService.Save();

                SetAlert(string.Format("The forge variant is saved.", variant.Title), AlertType.Success);
                return(RedirectToAction("Details", new { slug = variant.Slug }));
            }
            return(View(model));
        }