public ActionResult UpdateGame(int id = 0)
        {
            ProductDM    product = _mappers.ToProductDM.Map <ProductDTO, ProductDM>(_adminService.GetProduct(id));
            GameDM       result  = _mappers.ToGameDM.Map <GameDTO, GameDM>(_adminService.GetGame(product.FromTableId));
            GameCreateVM game    = new GameCreateVM()
            {
                IsThingGame        = result.IsThingGame,
                Name               = product.Name,
                SystemRequirements = result.SystemRequirements,
                Description        = product.Description,
                Sale               = product.Sale,
                Price              = product.Price
            };

            game.GameURL = result.Properties.First(g => g.Name == "Ссылка на игру").Value;
            game.Type    = result.Properties.First(g => g.Name == "Тип игры").Value;
            game.Genre   = result.Properties.First(g => g.Name == "Жанр игры").Value;
            if (product.Images != null && product.Images.FirstOrDefault() != null)
            {
                game.ImagesInDatebase = new List <ImageDM>();
                foreach (var i in product.Images)
                {
                    game.ImagesInDatebase.Add(i);
                    game.Alt = i.Text;
                }
            }
            return(View("CreateGame", game));
        }
        public ActionResult CreateGame(GameCreateVM item)
        {
            if (ModelState.IsValid)
            {
                GameDTO game = new GameDTO()
                {
                    Name = item.Name, GameURL = item.GameURL, Genre = item.Genre, IsThingGame = item.IsThingGame, Type = item.Type
                };
                if (item.Image != null)
                {
                    ImageDTO image = new ImageDTO();

                    image.Text = item.Alt;
                    using (var reader = new BinaryReader(item.Image.InputStream))
                        image.Photo = reader.ReadBytes(item.Image.ContentLength);

                    game.Images = new List <ImageDTO>();
                    game.Images.Add(image);
                }
                OperationDetails result = _service.ServiceForCRUD.CreateGame(game);
                ViewBag.Result = result.Message;
                ViewBag.Status = result.Succedeed;
                return(View());
            }
            return(View());
        }
示例#3
0
        public IActionResult GameDetails(GameCreateVM game)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(Index)));
            }
            var viewModel = service.StartGame(game.Name, game.SelectedNumberOfOpponents);

            service.AddWinnerToDatabase(viewModel.First());
            return(View(viewModel));
        }
 public ActionResult CreateGame(GameCreateVM item)
 {
     if (ModelState.IsValid)
     {
         ProductDTO product = new ProductDTO()
         {
             Name = item.Name, Description = item.Description, Price = item.Price, Sale = item.Sale
         };
         GameDTO game = new GameDTO();
         if (item.Images != null)
         {
             foreach (var i in item.Images)
             {
                 ImageDTO image = new ImageDTO();
                 image.Text = item.Alt;
                 using (var reader = new BinaryReader(i.InputStream))
                     image.Photo = reader.ReadBytes(i.ContentLength);
                 product.Images = new List <ImageDTO>();
                 product.Images.Add(image);
             }
         }
         else
         {
             product.Images = new List <ImageDTO>();
             foreach (var i in item.ImagesInDatebase)
             {
                 product.Images.Add(_mappers.ToImageDTO.Map <ImageDM, ImageDTO>(i));
             }
         }
         game.IsThingGame        = item.IsThingGame;
         game.SystemRequirements = item.SystemRequirements;
         game.Properties         = new List <PropertyDTO>();
         game.Properties.Add(new PropertyDTO()
         {
             Name = "Тип игры", Value = item.Type
         });
         game.Properties.Add(new PropertyDTO()
         {
             Name = "Ссылка на игру", Value = item.GameURL
         });
         game.Properties.Add(new PropertyDTO()
         {
             Name = "Жанр игры", Value = item.Genre
         });
         OperationDetails result = _adminService.CreateGame(product, game, product.Name);
         ViewBag.Result = result.Message;
         ViewBag.Status = result.Succedeed;
         return(View());
     }
     return(View());
 }