public ActionResult CreateSkinRarety(CreateSkinRarety item) { if (ModelState.IsValid) { SkinRarityDTO rarety = new SkinRarityDTO(); rarety.RarityName = item.RaretyName; List <ColorDTO> colors = new List <ColorDTO>(); foreach (var i in item.SelectedColors) { colors.Add(new ColorDTO() { Name = i }); } rarety.Colors = colors; OperationDetails result = _adminService.CreateSkinRarity(rarety, rarety.RarityName); ViewBag.Result = result.Message; ViewBag.Status = result.Succedeed; List <ColorDTO> colorsInDB = _adminService.GetColors().ToList(); item.Colors = colorsInDB.Select(x => new SelectListItem() { Text = x.Name, Value = x.Name }).ToList(); return(View(item)); } else { return(View()); } }
public OperationDetails CreateSkinRarity(SkinRarityDTO item, string oldSkinRarity) { if (item == null) { return(new OperationDetails(false, "ОбЪект ссылается на null", this.ToString())); } SkinRarity skinRarity = Database.SkinRareties.Find(x => x.RarityName == oldSkinRarity).FirstOrDefault(); List <Color> colors = new List <Color>(); foreach (var c in item.Colors) { Color color = Database.Colors.Find(cl => cl.Name == c.Name).FirstOrDefault(); if (color != null) { colors.Add(color); } } if (skinRarity != null) { skinRarity.Colors = colors; skinRarity.RarityName = item.RarityName; Database.SkinRareties.Update(skinRarity); Database.Save(); return(new OperationDetails(true, "Раритетность скина была успешно изменена", this.ToString())); } else { skinRarity = _mappers.ToSkinRarity.Map <SkinRarityDTO, SkinRarity>(item); skinRarity.Colors = colors; Database.SkinRareties.Add(skinRarity); Database.Save(); return(new OperationDetails(true, "Раритетность скина была успешно добавлена", this.ToString())); } }
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()); } }