Пример #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult EmployeeGamesCreate()
        {
            var list = GetDropDownItems();
            ViewBag.categories = list[0];
            ViewBag.platforms = list[1];
            ViewBag.publishers = list[2];
            ViewBag.ratings = list[3];
            var model = new CreateGameViewModel();

            return View("EmployeeGamesCreate", model);
        }
Пример #2
0
        public ActionResult Create(CreateGameViewModel gameViewModel)
        {
            if (ModelState.IsValid)
            {
                // Auto-map properties or manually?
                var game = new Models.Game();

                UoW.Games.Add(game);
                UoW.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(gameViewModel);
        }
Пример #3
0
        // GET: /Game/Create
        //[Authorize(Roles = "Admin")]
        public ActionResult Create()
        {
            // going to need:
            // categories as a checkbox
            // platforms as a check box
            // images uploader
            // publisher
            // summary as a textarea
            //
            var gameViewModel = new CreateGameViewModel();

            ViewBag.categories = UoW.Categories.GetAll();
            ViewBag.platforms = UoW.Platforms.GetAll();
            ViewBag.publishers = new SelectList(UoW.Publishers.GetAll(), "PublisherId", "Name");

            return View(gameViewModel);
        }
Пример #4
0
        public ActionResult EmployeeGamesCreate(CreateGameViewModel vm, FormCollection form, HttpPostedFileBase file)
        {
            // get all of the game info here...
            vm.Title = form["Title"];
            vm.Summary = form["Summary"];
            vm.PublisherId = Int32.Parse(form["publishers"]);
            vm.PlatformId = Int32.Parse(form["platforms"]);
            vm.CategoryId = Int32.Parse(form["categories"]);
            vm.RatingId = Int32.Parse(form["ratings"]);
            vm.ReleaseDate =  DateTime.Parse(form["ReleaseDate"]);
            vm.Price = decimal.Parse(form["Price"]);
            vm.IsDownloadable = bool.Parse(form["IsDownloadable"]);

            vm.Images = new List<Image>();

            if (file != null)
            {
                if (file.ContentLength == 0)
                {
                    vm.Images.Add(
                        new Image()
                        {
                            Name = "no-image",
                            Location = "/Content/GameImages/no-image.png",
                            isCover = true
                        });
                }
                else
                {
                    var fileName = Path.GetFileName(file.FileName);
                    var path = Path.Combine(Server.MapPath("/Content/GameImages/Covers/"), fileName);
                    file.SaveAs(path);
                    vm.Images.Add(
                        new Image()
                        {
                            Name = vm.Title,
                            Location = "/Content/GameImages/Covers/" + fileName,
                            isCover = true
                        });
                }
            }

            if (ModelState.IsValid)
            {
                if (!GameExists(vm.Title, vm.PublisherId, vm.PlatformId))
                {
                    Mapper.CreateMap<CreateGameViewModel, Models.Game>();

                    var game = Mapper.Map<CreateGameViewModel, Models.Game>(vm); // see hoe the GameId is treated. May be an error.

                    try
                    {
                        UoW.Games.Add(game);
                        UoW.SaveChanges();
                        return RedirectToAction("EmployeeGamesIndex");
                    }
                    catch
                    {
                        return View(vm);
                    }
                }
            }

            return View(vm);
        }