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 DeleteConfirmed(int id) { ProductDM product = serviceProducts.GetProduct(Convert.ToInt32(id)); serviceProducts.DeleteProduct(product); return(RedirectToAction("Index")); }
public void DeleteProduct(ProductDM productDM) { try { Product product = UOW.Products.Get(productDM.ProductID); foreach (Supply s in UOW.Supplies .Find(s => s.ProductID == product.ProductID)) { UOW.Supplies.Delete(s.SupplyID); } foreach (Sale s in UOW.Sales .Find(s => s.ProductID == product.ProductID)) { UOW.Supplies.Delete(s.SaleID); } UOW.Save(); UOW.Products.Delete(product.ProductID); UOW.Save(); } catch (Exception ex) { throw new DataException(ex.Message, "Error in deleting Product"); } }
public ProductView(ProductDM product) { ProductID = product.ProductID; Name = product.Name; Brand = product.Brand; CategoryID = product.CategoryID; Quantity = product.Quantity; Price = product.Price; Category = new Category(product.Category); }
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 int Save(ProductVM productVM) { //using (PHOTOLIODBContext context = new PHOTOLIODBContext()) //{ // int count = context.ProductDMs.Where(w => w.IsDelete == false && w.Name == productVM.Name).Count(); // if (count > 0) // { // return 100; // } //} var file = productVM.ImageFile; //byte[] imageByte = null; //BinaryReader reader = new BinaryReader(file.InputStream); //imageByte = reader.ReadBytes(file.ContentLength); string filename = string.Empty; if (file != null && file.ContentLength > 0) { filename = Path.GetFileName(file.FileName); string imgpath = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("/GALLERY/"), filename); file.SaveAs(imgpath); } long time = DateTime.Now.Ticks; ProductDM dmEntity = new ProductDM(); dmEntity.UserId = productVM.UserId; dmEntity.Photo = filename; dmEntity.Name = productVM.Name; dmEntity.Description = productVM.Description; dmEntity.Price = productVM.Price; dmEntity.CategoryId = productVM.CategoryId; dmEntity.Version = time; dmEntity.CreatedUserId = productVM.CreatedUserId; dmEntity.UpdatedUserId = productVM.UpdatedUserId; dmEntity.CreatedDate = time; dmEntity.UpdatedDate = time; int result = 0; using (PHOTOLIODBContext context = new PHOTOLIODBContext()) { context.ProductDMs.Add(dmEntity); result = context.SaveChanges(); } return(result); }
public void UpdateProduct(ProductDM productDM) { try { UOW.Products.Update(productDM.ToProduct()); UOW.Save(); } catch (Exception ex) { throw new DataException(ex.Message, "Error in updating Product"); } }
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 ProductEdit(ProductDM product, IEnumerable <CategoryDM> categories) { ProductID = product.ProductID; Name = product.Name; Brand = product.Brand; CategoryID = product.CategoryID; Quantity = product.Quantity; Price = product.Price; Category = new Category(product.Category); List <Category> productCategories = new List <Category>(); if (categories != null) { foreach (var c in categories) { productCategories.Add(new Category(c)); } } Categories = productCategories; }
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)); }
public ActionResult UpdateComputer(int id = 0) { ProductDM product = _mappers.ToProductDM.Map <ProductDTO, ProductDM>(_adminService.GetProduct(id)); ComputerDM result = _mappers.ToComputerDM.Map <ComputerDTO, ComputerDM>(_adminService.GetComputer(product.FromTableId)); CreateComputerVM comp = new CreateComputerVM() { Name = product.Name, Description = product.Description, Sale = product.Sale, Price = product.Price, SelectedMotherBoard = result.MotherBoard.Name, SelectedPowerSupply = result.PowerSupply.Name, SelectedProcessor = result.Processor.Name, SelectedSystemBlock = result.SystemBlock.Name }; comp.SelectedRAM = new List <string>(); foreach (var i in result.RAM) { comp.SelectedRAM.Add(i.Name); } comp.SelectedROM = new List <string>(); foreach (var i in result.ROM) { comp.SelectedROM.Add(i.Name); } comp.SelectedVideoCard = new List <string>(); foreach (var i in result.VideoCard) { comp.SelectedVideoCard.Add(i.Name); } if (product.Images != null && product.Images.FirstOrDefault() != null) { comp.ImagesInDatebase = new List <ImageDM>(); foreach (var i in product.Images) { comp.ImagesInDatebase.Add(i); comp.Alt = i.Text; } } List <ComputerComponentDM> compMotherBoard = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.MotherBoard)); var compMotherBoardItems = compMotherBoard.Select(x => new SelectListItem() { Text = x.Name, Value = x.Name }).ToList(); List <ComputerComponentDM> compPowerSupply = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.PowerSupply)); var compPowerSupplyItems = compPowerSupply.Select(x => new SelectListItem() { Text = x.Name, Value = x.Name }).ToList(); List <ComputerComponentDM> compProcessor = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.Processor)); var compProcessorItems = compProcessor.Select(x => new SelectListItem() { Text = x.Name, Value = x.Name }).ToList(); List <ComputerComponentDM> compRAM = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.RAM)); var compRAMItems = compRAM.Select(x => new SelectListItem() { Text = x.Name, Value = x.Name }).ToList(); List <ComputerComponentDM> compROM = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.ROM)); var compROMItems = compROM.Select(x => new SelectListItem() { Text = x.Name, Value = x.Name }).ToList(); List <ComputerComponentDM> compSystemBlock = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.SystemBlock)); var compSystemBlockItems = compSystemBlock.Select(x => new SelectListItem() { Text = x.Name, Value = x.Name }).ToList(); List <ComputerComponentDM> compVideoCard = _mappers.ToComputerComponentDM.Map <ICollection <ComputerComponentDTO>, List <ComputerComponentDM> >(_adminService.GetComputerComponentsByType(ComponentType.VideoCard)); var compVideoCardItems = compVideoCard.Select(x => new SelectListItem() { Text = x.Name, Value = x.Name }).ToList(); comp.MotherBoards = compMotherBoardItems; comp.PowerSupplies = compPowerSupplyItems; comp.Processors = compProcessorItems; comp.RAMs = compRAMItems; comp.ROMs = compROMItems; comp.SystemBlocks = compSystemBlockItems; comp.VideoCards = compVideoCardItems; return(View("CreateComputer", comp)); }
public void AddProduct(ProductDM productDM) { UOW.Products.Create(productDM.ToProductNoID()); UOW.Save(); }