public ActionResult CreateCloth() { List <ColorDM> colors = _mappers.ToColorDM.Map <ICollection <ColorDTO>, List <ColorDM> >(_adminService.GetColors()); var colorItems = colors.Select(x => new SelectListItem() { Text = x.Name, Value = x.Name }).ToList(); CreateClothVM cloth = new CreateClothVM(); cloth.Colors = colorItems; return(View(cloth)); }
public ActionResult UpdateCloth(int id = 0) { ProductDM product = _mappers.ToProductDM.Map <ProductDTO, ProductDM>(_adminService.GetProduct(id)); ClothDM result = _mappers.ToClothDM.Map <ClothDTO, ClothDM>(_adminService.GetCloth(product.FromTableId)); CreateClothVM cloth = new CreateClothVM() { Name = product.Name, Description = product.Description, Sale = product.Sale, Price = product.Price, Composition = result.Composition, Type = result.Type }; if (result.ForMen) { cloth.ForMen = "Для мужчин"; } else { cloth.ForMen = "Для женщин"; } cloth.Properties = result.Properties; cloth.SelectedColors = new List <string>(); foreach (var c in result.Colors) { cloth.SelectedColors.Add(c.Name); } cloth.Sizes = new List <string>(); foreach (var s in result.Sizes) { cloth.Sizes.Add(s.Data); } if (product.Images != null && product.Images.FirstOrDefault() != null) { cloth.ImagesInDatebase = new List <ImageDM>(); foreach (var i in product.Images) { cloth.ImagesInDatebase.Add(i); cloth.Alt = i.Text; } } List <ColorDM> colors = _mappers.ToColorDM.Map <ICollection <ColorDTO>, List <ColorDM> >(_adminService.GetColors()); var colorItems = colors.Select(x => new SelectListItem() { Text = x.Name, Value = x.Name }).ToList(); cloth.Colors = colorItems; return(View("CreateCloth", cloth)); }
public ActionResult CreateCloth(CreateClothVM item) { if (ModelState.IsValid) { ProductDTO product = new ProductDTO() { Name = item.Name, Description = item.Description, Price = item.Price, Sale = item.Sale }; ClothDTO cloth = new ClothDTO(); 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 { foreach (var i in item.ImagesInDatebase) { product.Images = new List <ImageDTO>(); product.Images.Add(_mappers.ToImageDTO.Map <ImageDM, ImageDTO>(i)); } } cloth.Composition = item.Composition; if (item.ForMen == "Для мужчин") { cloth.ForMen = true; } else { cloth.ForMen = false; } cloth.Name = item.Name; cloth.Type = item.Type; cloth.Properties = _mappers.ToPropertyDTO.Map <ICollection <PropertyDM>, List <PropertyDTO> >(item.Properties); cloth.Colors = new List <ColorDTO>(); foreach (var i in item.SelectedColors) { cloth.Colors.Add(new ColorDTO() { Name = i }); } cloth.Sizes = new List <StringDataDTO>(); foreach (var i in item.Sizes) { cloth.Sizes.Add(new StringDataDTO() { Data = i }); } OperationDetails result = _adminService.CreateCloth(product, cloth, product.Name); ViewBag.Result = result.Message; ViewBag.Status = result.Succedeed; List <ColorDM> colors = _mappers.ToColorDM.Map <ICollection <ColorDTO>, List <ColorDM> >(_adminService.GetColors()); var colorItems = colors.Select(x => new SelectListItem() { Text = x.Name, Value = x.Name }).ToList(); item.Colors = colorItems; return(View(item)); } return(View()); }