public ActionResult UpdateComputerComponent(int id = 0)
        {
            ProductDM                 product  = _mappers.ToProductDM.Map <ProductDTO, ProductDM>(_adminService.GetProduct(id));
            ComputerComponentDM       result   = _mappers.ToComputerComponentDM.Map <ComputerComponentDTO, ComputerComponentDM>(_adminService.GetComputerComponent(product.FromTableId));
            CreateComputerComponentVM compComp = new CreateComputerComponentVM()
            {
                Name        = product.Name,
                Description = product.Description,
                Sale        = product.Sale,
                Price       = product.Price
            };

            switch (result.Type)
            {
            case ComponentType.VideoCard:
                compComp.Type = "Видеокарта";
                break;

            case ComponentType.MotherBoard:
                compComp.Type = "Материнская плата";
                break;

            case ComponentType.PowerSupply:
                compComp.Type = "Блок питания";
                break;

            case ComponentType.Processor:
                compComp.Type = "Процессор";
                break;

            case ComponentType.RAM:
                compComp.Type = "Оперативная память";
                break;

            case ComponentType.ROM:
                compComp.Type = "Постоянная память";
                break;

            case ComponentType.SystemBlock:
                compComp.Type = "Системный блок";
                break;
            }
            if (product.Images != null && product.Images.FirstOrDefault() != null)
            {
                compComp.ImagesInDatebase = new List <ImageDM>();
                foreach (var i in product.Images)
                {
                    compComp.ImagesInDatebase.Add(i);
                    compComp.Alt = i.Text;
                }
            }
            return(View("CreateComputerComponent", compComp));
        }
        public ActionResult CreateComputerComponent(CreateComputerComponentVM item)
        {
            if (ModelState.IsValid)
            {
                ProductDTO product = new ProductDTO()
                {
                    Name = item.Name, Description = item.Description, Price = item.Price, Sale = item.Sale
                };
                ComputerComponentDTO compComp = new ComputerComponentDTO();
                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));
                    }
                }
                switch (item.Type)
                {
                case "Видеокарта":
                    compComp.Type = ComponentType.VideoCard;
                    break;

                case "Материнская плата":
                    compComp.Type = ComponentType.MotherBoard;
                    break;

                case "Блок питания":
                    compComp.Type = ComponentType.PowerSupply;
                    break;

                case "Процессор":
                    compComp.Type = ComponentType.Processor;
                    break;

                case "Оперативная память":
                    compComp.Type = ComponentType.RAM;
                    break;

                case "Постоянная память":
                    compComp.Type = ComponentType.ROM;
                    break;

                case "Системный блок":
                    compComp.Type = ComponentType.SystemBlock;
                    break;
                }
                compComp.Properties = _mappers.ToPropertyDTO.Map <ICollection <PropertyDM>, ICollection <PropertyDTO> >(item.Properties);
                OperationDetails result = _adminService.CreateComputerComponent(product, compComp, product.Name);
                ViewBag.Result = result.Message;
                ViewBag.Status = result.Succedeed;
                return(View());
            }
            return(View());
        }