public ActionResult Details(int id, GameTypeVariant model)
        {
            var variant = GameTypeService.GetVariant(id);

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

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

                GameTypeService.Save();

                this.SetAlert(string.Format("The variant '{0}' has been updated.", variant.Title), AlertType.Success);
                return(RedirectToAction("Index"));
            }
            return(View(variant));
        }
        public void GameType(int id, string token)
        {
            if (!TokenService.ValidateDateTimeToken(token))
            {
                Response.StatusCode = 403;
                Response.End();
                return;
            }

            var variant = GameTypeService.GetVariant(id);

            variant.File.Downloads.Add(new FileDownload()
            {
                DownloadedOn = DateTime.UtcNow,
                UserId       = Request.IsAuthenticated ? (int?)User.Identity.GetUserId <int>() : null,
                UserIP       = Request.UserHostAddress
            });
            variant.File.DownloadCount += 1;
            GameTypeService.Save();

            Response.ContentType = "application/octet-stream";
            Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + variant.DownloadName);
            Response.TransmitFile(Path.Combine(Server.MapPath("~/Content/Files/GameType"), variant.File.FileName));
            Response.End();
        }
        public ActionResult Delete(int id, GameTypeVariant model)
        {
            var variant = GameTypeService.GetVariant(id);

            variant.IsDeleted = !variant.IsDeleted;
            GameTypeService.Save();

            this.SetAlert(string.Format("The variant '{0}' has been deleted.", variant.Title), AlertType.Success);
            return(RedirectToAction("Index"));
        }
Exemple #4
0
        public ActionResult Edit(int id)
        {
            var variant = GameTypeService.GetVariant(id);

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

            return(View(variant));
        }
        public ActionResult Delete(int id)
        {
            var variant = GameTypeService.GetVariant(id);

            if (variant == null)
            {
                return(HttpNotFound());
            }

            return(View(variant));
        }
Exemple #6
0
        public ActionResult Reply(ViewModels.ReplyRequest model)
        {
            var variant = GameTypeService.GetVariant(model.Id);

            if (ModelState.IsValid)
            {
                int id = GameTypeService.Reply(model, User.Identity.GetUserId <int>());

                return(new RedirectResult(Url.Action("Details", new { slug = variant.Slug }) + "#reactions-" + id));
            }
            SetAlert("<strong>PARDON OUR DUST!</strong> Something went wrong when trying to reply, please try again.", AlertType.Danger);

            return(RedirectToAction("Details", new { slug = variant.Slug }));
        }
Exemple #7
0
        public ActionResult Delete(int id, GameTypeVariant model)
        {
            var variant = GameTypeService.GetVariant(id);

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

            variant.IsDeleted = true;
            GameTypeService.Save();

            SetAlert(string.Format("The game variant {0} is deleted.", variant.Title), AlertType.Success);
            return(RedirectToAction("Index"));
        }
Exemple #8
0
        public ActionResult GameType(int id)
        {
            var variant = GameTypeService.GetVariant(id);

            if (variant == null || variant.IsDeleted)
            {
                return(HttpNotFound());
            }

            return(Json(new
            {
                Type = "GameType",
                TypeName = variant.GameType.Name,
                Id = variant.Id,
                Name = variant.Title,
                Author = variant.Author.UserName,
                Description = variant.ShortDescription,
                Icon = @"/content/images/gametypes/thumbs/" + variant.GameType.InternalName + ".png",
                Download = Url.Action("Forge", "Download", new { id = variant.Id, token = TokenService.CreateDateTimeToken() }),
                Provider = "HaloShare",
                ProviderIcon = "/content/images/logo/white.png"
            }, JsonRequestBehavior.AllowGet));
        }
Exemple #9
0
        public ActionResult Edit(int id, Models.GameTypeVariant model)
        {
            if (ModelState.IsValid)
            {
                var variant = GameTypeService.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;

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

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

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

                GameTypeService.Save();

                SetAlert(string.Format("The game variant is saved.", variant.Title), AlertType.Success);
                return(RedirectToAction("Details", new { slug = variant.Slug }));
            }
            return(View(model));
        }
Exemple #10
0
 public ActionResult Details(int slug)
 {
     ViewBag.Token = TokenService.CreateDateTimeToken();
     return(View(GameTypeService.GetVariant(slug)));
 }