public async Task <IActionResult> DeleteConfirmed(string id, [Bind("ItemId, Name, Size, ColorId, BrandId, Price, Image, Stock,State")] Sneaker sneaker) { if (ModelState.IsValid) { try { sneaker.State = 0; _context.Update(sneaker); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SneakerExists(sneaker.ItemId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Index))); }
public void ParseSneakersFromPage(Catalog catalog, string link, string sex, string category) { Console.WriteLine("Парсим " + link); Uri uri = new Uri(link); WebClient webClient = new WebClient(); webClient.Encoding = Encoding.UTF8; string source = webClient.DownloadString(uri); webClient.Dispose(); var parser = new HtmlParser(); var document = parser.Parse(source); var items = document.QuerySelectorAll("a.product-item__title_a"); foreach (var item in items) { var sneaker = new Sneaker(); sneaker.sex = sex; sneaker.category = category; sneaker.link = item.GetAttribute("href"); if (!catalog.isExistSneakerInCatalog(sneaker)) { catalog.sneakers.Add(sneaker); } } }
public async Task <IActionResult> AddSneaker(Sneaker obj) { try { if (ModelState.IsValid) { if (obj.Id == 0) { _appDBContent.Sneakers.Add(obj); await _appDBContent.SaveChangesAsync(); } else { _appDBContent.Entry(obj).State = EntityState.Modified; await _appDBContent.SaveChangesAsync(); } return(RedirectToAction("SneakersList")); } return(View()); } catch (Exception ex) { return(RedirectToAction("SneakersList")); } }
public async Task <IActionResult> Add(SneakerAddViewModel model) { model.BrandsList = savm.BrandsList; if (ModelState.IsValid) { string FileName = null; string Folder = Path.Combine(webHost.WebRootPath, "Images"); FileName = Guid.NewGuid().ToString() + "_" + model.Picture.FileName; string FilePath = Path.Combine(Folder, FileName); await model.Picture.CopyToAsync(new FileStream(FilePath, FileMode.Create)); model.PicturePath = FileName; var sneaker = new Sneaker() { Name = model.Name, BrandId = model.BrandId, Price = model.Price, Count = model.Count, Color = model.Color, PicturePath = FileName }; await context.Sneakers.AddAsync(sneaker); await context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(model)); }
public void SaveStockToCSV(string FileName) { string filenameCatalog = FileName; int count = this.sneakers.Count; var stock = new OnlineShopStock(); //List<StockRecord> stock = new List<StockRecord>(); for (int i = 0; i < count; i++) { for (int j = 0; j < this.sneakers[i].sizes.Count; j++) { StockRecord record = new StockRecord(); Sneaker sneaker = this.sneakers[i]; record.sku = sneaker.sku; record.upc = sneaker.sizes[j].upc; record.title = sneaker.title; record.price = sneaker.price; record.oldPrice = sneaker.oldPrice; record.sellPrice = sneaker.sellPrice; record.quantity = 1; record.link = sneaker.link; record.size = sneaker.sizes[j].sizeUS; stock.records.Add(record); } } stock.SaveStockToCSV(FileName); }
public int RemoveFromCart(Sneaker sneaker) { var shoppingCartItem = _context.ShoppingCartItems.SingleOrDefault( s => s.Sneaker.SneakerID == sneaker.SneakerID && s.ShoppingCartID == ShoppingCartID); var localAmount = 0; if (shoppingCartItem != null) { if (shoppingCartItem.Amount > 1) { shoppingCartItem.Amount--; localAmount = shoppingCartItem.Amount; } else { _context.ShoppingCartItems.Remove(shoppingCartItem); } } _context.SaveChanges(); return(localAmount); }
public async Task <IActionResult> Create([Bind("SneakerId,BrandCategoryId,ModelName,ReleaseYear,Description,Material,Price,InStock")] Sneaker sneaker, IFormFile Image) { if (ModelState.IsValid) { //Validation for adding photos to the create form. //Check for a photo and upload if (Image.Length > 0) { //get a temp location of the upload file var tempFile = Path.GetTempFileName(); //create a unique name using a global unique ID (GUID) var fileName = Guid.NewGuid() + "-" + Image.FileName; //set the destination - dynamic - PATH and file name - one slah is not recognised as a path. var uploadPath = System.IO.Directory.GetCurrentDirectory() + "\\wwwroot\\img\\sneaker_upload\\" + fileName; //using a STREAM to create a new file using var stream = new FileStream(uploadPath, FileMode.Create); await Image.CopyToAsync(stream); //Add unique file name as the photo property of the new Product object sneaker.Image = fileName; } _context.Add(sneaker); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BrandCategoryId"] = new SelectList(_context.BrandCategories, "BrandCategoryId", "BrandName", sneaker.BrandCategoryId); return(View(sneaker)); }
public Sneaker ParseOneSneaker(string url) { var sneaker = new Sneaker(); sneaker.link = url; return(ParseOneSneaker(sneaker)); }
public async Task <IActionResult> Edit(int?id) { if (id != null) { Sneaker sneakers = await context.Sneakers.FirstOrDefaultAsync(s => s.Id == id); SneakerAddViewModel model = new SneakerAddViewModel() { BrandsList = savm.BrandsList, SneakerId = sneakers.Id, Name = sneakers.Name, BrandId = sneakers.BrandId, Price = sneakers.Price, Color = sneakers.Color, Count = sneakers.Count, PicturePath = sneakers.PicturePath }; if (model != null) { return(View(model)); } } return(NotFound()); }
public void ParseSneakersFromPage(Catalog catalog, string link) { Console.WriteLine("Парсим " + link); Uri uri = new Uri(link); string source = new WebClient().DownloadString(uri); var parser = new HtmlParser(); var document = parser.Parse(source); var items = document.QuerySelectorAll("div.item"); foreach (var item in items) { var sneaker = new Sneaker(); sneaker.sku = item.QuerySelector("div.art").InnerHtml; var priceDiv = item.QuerySelector("div.price"); string priceStr; if (priceDiv.QuerySelector("span.ssale") != null) { priceStr = priceDiv.QuerySelector("span.ssale").InnerHtml; sneaker.price = Int32.Parse(priceStr.Replace("р.", "")); sneaker.oldPrice = Int32.Parse(priceDiv.QuerySelector("s").InnerHtml); } else { priceStr = priceDiv.InnerHtml; sneaker.price = Int32.Parse(priceStr.Replace("р.", "")); } //из заголовка еще надо вытащить type и убрать nike sneaker.title = item.QuerySelector("span.name").InnerHtml; sneaker.ParseTitle(); sneaker.link = SITEURL + item.QuerySelector("a").GetAttribute("href"); sneaker.brand = this.brand; //sizes string[] sizesStrArr = item.QuerySelector("div.item_sizes").InnerHtml.Split(','); foreach (var size in sizesStrArr) { SneakerSize sneakerSize = new SneakerSize(sneaker, size.Trim()); sneaker.sizes.Add(sneakerSize); } //catalog.sneakers.Add(stockSneaker); catalog.AddUniqueSneaker(sneaker); } //next page var nextlinks = document.QuerySelector("div.pages").QuerySelectorAll("a.arrow"); foreach (var nextlink in nextlinks) { if (nextlink.ClassName == "arrow r") { string nextPageLink = nextlink.GetAttribute("href"); Thread.Sleep(100); ParseSneakersFromPage(catalog, SITEURL + nextPageLink); } } }
public IActionResult UpdateSneaker([FromRoute] int id, [FromBody] Sneaker sneaker) { if (_daoSneakers.Update(id, sneaker) == 0) { return(NotFound()); } return(Ok()); }
public IActionResult CreateSneaker([FromBody] Sneaker sneaker) { if (_daoSneakers.Create(sneaker) == 0) { return(StatusCode(500)); } return(Ok()); }
private SneakerViewModel MapDbSneakerToSneakerViewModel(Sneaker dbSneaker) => new SneakerViewModel { SneakerID = dbSneaker.SneakerID, Name = dbSneaker.Name, Price = dbSneaker.Price, ShortDescription = dbSneaker.ShortDescription, ImageThumbnailUrl = dbSneaker.ImageThumbnailUrl };
private void btnAddNumberQuantity_Click(object sender, EventArgs e) { sneaker = new Sneaker { Number = numUpDownNumber.Value, Quantity = numUpDownQuantity.Value }; Visible = false; }
public ActionResult <Sneaker> GetSneaker(int id) { Sneaker sneaker = _sneakerRepository.FindById(id); if (sneaker == null) { return(NotFound()); } return(Ok(sneaker)); }
public async Task <ActionResult <Sneaker> > AddSneaker(Sneaker sneaker) { if (sneaker != null) { return(await _sneakerService.AddSneaker(sneaker)); } else { return(new BadRequestResult()); } }
public async Task <IActionResult> Create([Bind("ItemId,Name,Size,ColorId,BrandId,Price,Image,Stock,State")] Sneaker sneaker) { if (ModelState.IsValid) { sneaker.State = 1; // Mỗi sản phẩm được tạo ra đều được gán State = 1 để hiển thị sự tồn tại của nó _context.Add(sneaker); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(sneaker)); }
public IActionResult DeleteSneaker(int id) { Sneaker sneaker = _sneakerRepository.FindById(id); if (sneaker == null) { return(NotFound()); } _sneakerRepository.Delete(sneaker); _sneakerRepository.SaveChanges(); return(NoContent()); }
public async Task <IActionResult> ConfirmRemove(int?id) { if (id != null) { Sneaker sneakers = await context.Sneakers.FirstOrDefaultAsync(s => s.Id == id); if (sneakers != null) { return(View(sneakers)); } } return(NotFound()); }
public IActionResult AddStock(int id, StockDTO stock) { Sneaker sneaker = _sneakerRepository.FindById(id); if (sneaker == null) { return(NotFound()); } sneaker.AddStock(stock.Size, stock.Amount); _sneakerRepository.SaveChanges(); return(NoContent()); }
public void AddUniqueSneaker(Sneaker sneaker) { //if (Validator.ValidateSku(sneaker.sku, sneaker.brand)) //{ if (!this.isExistSneakerInCatalog(sneaker)) { this.sneakers.Add(sneaker); } //} //else //{ //Program.Logger.Warn("Catalog.AddUniqueSneaker. Artikul is Invalid. sku: " + sneaker.sku); //} }
public void ParseSneakersFromPage(Catalog catalog, string link, string sex, string category) { Console.WriteLine("Парсим " + link); Uri uri = new Uri(link); WebClient webClient = new WebClient(); webClient.Encoding = Encoding.UTF8; string source = webClient.DownloadString(uri); webClient.Dispose(); var parser = new HtmlParser(); var document = parser.Parse(source); var items = document.QuerySelectorAll("div.ms2_product"); foreach (var item in items) { var sneaker = new Sneaker(); sneaker.sex = sex; sneaker.category = category; sneaker.link = SITEURL + "/" + item.QuerySelector("a").GetAttribute("href"); //title sneaker.title = item.QuerySelector("span.item-txt").InnerHtml; sneaker.ParseTitle(); //stockSneaker.title = stockSneaker.brand + " " + stockSneaker.title.Replace(stockSneaker.brand, "").Trim(); sneaker.title = sneaker.title.Replace("Jordan AIR JORDAN", "AIR JORDAN"); sneaker.title = sneaker.title.Replace("Jordan JORDAN", "AIR JORDAN"); //price string priceString = item.QuerySelector("div.item-price").InnerHtml.Replace("<!--h5>RUB</h5-->", "").Replace("RUB", "").Trim().Replace(" ", ""); sneaker.price = Double.Parse(priceString); //sizes string sizeString = item.QuerySelector("div.size-box").InnerHtml.Replace("US", ""); sizeString = sizeString.Replace("UK", ""); //есть один артикул у которого вместо US UK string[] stringSeparators = new string[] { "\n" }; string[] sizeArr = sizeString.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries); foreach (var size in sizeArr) { if (!String.IsNullOrWhiteSpace(size)) { SneakerSize snSize = new SneakerSize(size.Trim()); sneaker.sizes.Add(snSize); } } sneaker.DeleteDuplicateSizes(); catalog.AddUniqueSneaker(sneaker); } }
public IActionResult AddBrand(int brandId, int sneakerId) { Sneaker sneaker = _sneakerRepository.FindById(sneakerId); Brand brand = _brandRepository.FindById(brandId); if (sneaker == null || brand == null) { return(NotFound()); } sneaker.AddBrand(brand); _sneakerRepository.SaveChanges(); return(NoContent()); }
public SneakerModel(Sneaker enemy) : base(enemy) { this.sneaker = enemy; model = ModelLibrary.sneFly; scale = new Vector3(.1f); setAnims(); activeClip = fly; animPlayer.StartClip(activeClip); SetupEffects(); }
public IActionResult PutSneaker(int id, Sneaker sneaker) { if (_sneakerRepository.FindById(id) == null) { return(NotFound()); } if (id != sneaker.Id) { return(BadRequest()); } _sneakerRepository.Update(sneaker); _sneakerRepository.SaveChanges(); return(NoContent()); }
public void MergeCatalogAndStock() { foreach (var size in stock.records) { Sneaker sneaker = catalog.GetSneakerFromSKU(size.sku); if (sneaker == null) { Program.Logger.Warn("нет в каталоге: " + size.sku); } else { sneaker.sizes.Add(new SneakerSize(size.size)); } } }
public async Task <Sneaker> AddSneaker(Sneaker sneaker) { try { sneaker.SneakerId = Guid.NewGuid(); await _context.Sneakers.AddAsync(sneaker); await _context.SaveChangesAsync(); return(sneaker); } catch (Exception ex) { return(null); } }
public bool isExistSneakerInCatalog(Sneaker sneaker) { if (sneaker.sku == null) //если sku null то ищем дубликаты по ссылке { if (GetIndexFromLink(sneaker.link) == -1) { return(false); } } else //если есть sku то ищем дубликаты по нему if (GetIndexFromSKU(sneaker.sku) == -1) { return(false); } return(true); }
public List <Sneaker> GetListSneaker() { List <Sneaker> list = new List <Sneaker>(); string query = "select * from Sneaker"; DataTable data = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { Sneaker sneaker = new Sneaker(item); list.Add(sneaker); } return(list); }
public List <Sneaker> SearchSneakerByName(string name) { List <Sneaker> list = new List <Sneaker>(); string query = string.Format("SELECT * FROM dbo.Sneaker WHERE dbo.fuConvertToUnsign1(name) LIKE N'%' + dbo.fuConvertToUnsign1(N'{0}') + '%'", name); DataTable data = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { Sneaker sneaker = new Sneaker(item); list.Add(sneaker); } return(list); }
public async Task <IActionResult> Remove(int?id) { if (id != null) { Sneaker sneakers = await context.Sneakers.FirstOrDefaultAsync(s => s.Id == id); if (sneakers != null) { context.Sneakers.Remove(sneakers); await context.SaveChangesAsync(); return(RedirectToAction("Index")); } } return(NotFound()); }