Ejemplo n.º 1
0
        public ActionResult CreateSkin()
        {
            List <GameDM> games     = _mappers.ToGameDM.Map <ICollection <GameDTO>, List <GameDM> >(_adminService.GetGames());
            var           gameItems = games.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            List <SkinRaretyDM> skinRar = _mappers.ToSkinRarityDM.Map <ICollection <SkinRarityDTO>, List <SkinRaretyDM> >(_adminService.GetSkinRarities());
            var skinRarityItems         = skinRar.Select(x => new SelectListItem()
            {
                Text = x.RarityName, Value = x.RarityName
            }).ToList();
            SkinCreateVM skin = new SkinCreateVM();

            skin.Games        = gameItems;
            skin.SkinRarities = skinRarityItems;
            return(View(skin));
        }
Ejemplo n.º 2
0
        public ActionResult UpdateSkin(int id = 0)
        {
            ProductDM    product = _mappers.ToProductDM.Map <ProductDTO, ProductDM>(_adminService.GetProduct(id));
            SkinDM       result  = _mappers.ToSkinDM.Map <SkinDTO, SkinDM>(_adminService.GetSkin(product.FromTableId));
            SkinCreateVM skin    = new SkinCreateVM()
            {
                Description = product.Description,
                Game        = result.Game.Name,
                Name        = product.Name,
                Price       = product.Price,
                Sale        = product.Sale,
                SkinRarity  = result.SkinRarity.RarityName,
                SkinType    = result.Properties.FirstOrDefault().Name
            };

            if (product.Images != null && product.Images.FirstOrDefault() != null)
            {
                skin.ImagesInDatebase = new List <ImageDM>();
                foreach (var i in product.Images)
                {
                    skin.ImagesInDatebase.Add(i);
                    skin.Alt = i.Text;
                }
            }
            List <GameDM> games     = _mappers.ToGameDM.Map <ICollection <GameDTO>, List <GameDM> >(_adminService.GetGames());
            var           gameItems = games.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Name
            }).ToList();
            List <SkinRaretyDM> skinRar = _mappers.ToSkinRarityDM.Map <ICollection <SkinRarityDTO>, List <SkinRaretyDM> >(_adminService.GetSkinRarities());
            var skinRarityItems         = skinRar.Select(x => new SelectListItem()
            {
                Text = x.RarityName, Value = x.RarityName
            }).ToList();

            skin.Games        = gameItems;
            skin.SkinRarities = skinRarityItems;
            return(View("CreateSkin", skin));
        }
Ejemplo n.º 3
0
 public ActionResult CreateSkin(SkinCreateVM item)
 {
     if (ModelState.IsValid)
     {
         ProductDTO product = new ProductDTO()
         {
             Name = item.Name, Price = item.Price, Sale = item.Sale
         };
         SkinDTO skin = new SkinDTO();
         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));
             }
         }
         if (item.Game != "")
         {
             skin.Game = new GameDTO()
             {
                 Name = item.Game
             }
         }
         ;
         if (item.SkinRarity != "")
         {
             SkinRarityDTO skinRarity = new SkinRarityDTO()
             {
                 RarityName = item.SkinRarity
             };
             skin.SkinRarity = skinRarity;
         }
         if (item.SkinType != "")
         {
             PropertyDTO skinType = new PropertyDTO()
             {
                 Name = "Тип скина", Value = item.SkinType
             };
             skin.Properties = new List <PropertyDTO>();
             skin.Properties.Add(skinType);
         }
         if (item.Description != "")
         {
             product.Description = item.Description;
         }
         OperationDetails result = _adminService.CreateSkin(product, skin, product.Name);
         ViewBag.Result = result.Message;
         ViewBag.Status = result.Succedeed;
         List <GameDM> games     = _mappers.ToGameDM.Map <ICollection <GameDTO>, List <GameDM> >(_adminService.GetGames());
         var           gameItems = games.Select(x => new SelectListItem()
         {
             Text = x.Name, Value = x.Name
         }).ToList();
         List <SkinRaretyDM> skinRar = _mappers.ToSkinRarityDM.Map <ICollection <SkinRarityDTO>, List <SkinRaretyDM> >(_adminService.GetSkinRarities());
         var skinRarityItems         = skinRar.Select(x => new SelectListItem()
         {
             Text = x.RarityName, Value = x.RarityName
         }).ToList();
         item.Games        = gameItems;
         item.SkinRarities = skinRarityItems;
         return(View(item));
     }
     else
     {
         return(View());
     }
 }
        public ActionResult CreateSkin([Bind(Include = "Game")] SkinCreateVM item)
        {
            if (ModelState.IsValid)
            {
                SkinDTO skin = new SkinDTO()
                {
                    Name = item.Name, Price = item.Price, Sale = item.Sale
                };

                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);

                    skin.Images = new List <ImageDTO>();
                    skin.Images.Add(image);
                }
                if (item.Game != "")
                {
                    skin.Game = new GameDTO()
                    {
                        Name = item.Game
                    }
                }
                ;

                if (item.SkinRarity != "")
                {
                    SkinRarityDTO skinRarity = new SkinRarityDTO()
                    {
                        Color = item.SkinRarityColor, RarityName = item.SkinRarity
                    };
                    skin.SkinRarity = skinRarity;
                }

                if (item.SkinType != "")
                {
                    SkinTypeDTO skinType = new SkinTypeDTO()
                    {
                        TypeName = item.SkinType
                    };
                    skin.SkinType = skinType;
                }

                if (item.Description != "")
                {
                    skin.Description = item.Description;
                }

                OperationDetails result = _service.ServiceForCRUD.CreateSkin(skin);
                ViewBag.Result = result.Message;
                ViewBag.Status = result.Succedeed;
                return(View());
            }
            else
            {
                return(View());
            }
        }