public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(BoughtItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BoughtItemExists(BoughtItem.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(string name, string address, string city, string state, int zip) { ddsCookie = Request.Cookies["ddsCookie"]; Console.WriteLine(" INSIDE ASYNC TASK POST"); var items = _context.Item.Where(t => cookieResults.Contains(t.ID)); decimal totPrice = 0m; foreach (Item i in items) { totPrice += i.Price; } Order order = new Order { Name = name, StreetAddress = address, City = city, State = state, Zipcode = zip, Price = (decimal)Math.Round(totPrice, 2) }; _context.Order.Add(order); foreach (Item i in items) { _context.BoughtItem.Add(convertItem(i, order.ID)); _context.Item.Remove(i); } await _context.SaveChangesAsync(); return(RedirectToPage("./OrderConfirmation")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Item = await _context.Item.Include(s => s.Images).FirstOrDefaultAsync(i => i.ID == id); if (Item != null) { // var fileName = this.Item.ImageName; // var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads"); // var filePath = Path.Combine(uploads, fileName); String uploadFolder = "uploads"; String newDir = "ImageFolder_" + Item.FID; var uploadPath = Path.Combine(_hostingEnvironment.WebRootPath, uploadFolder); var newDirPath = Path.Combine(uploadPath, newDir); _context.Item.Remove(Item); if (Directory.Exists(newDirPath)) { Directory.Delete(newDirPath, true); } await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.BoughtItem.Add(BoughtItem); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { Item.FID = generateID(); if (!ModelState.IsValid) { return(Page()); } ArrayList images = new ArrayList(); if (this.Image != null) { String uploadFolder = "uploads"; String newDir = "ImageFolder_" + Item.FID; var uploadPath = Path.Combine(_hostingEnvironment.WebRootPath, uploadFolder); var newDirPath = Path.Combine(uploadPath, newDir); if (!Directory.Exists(newDirPath)) { Directory.CreateDirectory(newDirPath); } foreach (IFormFile f in Image) { var fileName = f.FileName; // there needs to be validation on filename var filePath = Path.Combine(newDirPath, fileName); FileStream stream = new FileStream(filePath, FileMode.Create); f.CopyTo(stream); stream.Close(); var filePath2 = Path.Combine(Path.Combine(uploadFolder, newDir), fileName); images.Add(new Image { ImageURL = filePath2 }); } } Item.Tags = standardizeTags(Item.Tags); _context.Item.Add(Item); Item.Price = (decimal)Item.Price; foreach (Image i in images) { i.ItemID = Item.ID; _context.Image.Add(i); } await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } BoughtItem = await _context.BoughtItem.FindAsync(id); if (BoughtItem != null) { _context.BoughtItem.Remove(BoughtItem); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Image = await _context.Image.FindAsync(id); if (Image != null) { _context.Image.Remove(Image); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnGetAsync(string name, string address, string city, string state, int zip) { ddsCookie = Request.Cookies["ddsCookie"]; this.cookieResults = this.parseCookieResults(CartModel.ddsCookie);//ddsCookie.Split(',').ToList(); var items = _context.Item.Where(t => cookieResults.Contains(t.ID)); Item = await items.ToListAsync(); // Items = items.ToList(); Console.WriteLine(Item.Count); decimal totPrice = 0; foreach (Item i in items) { totPrice += i.Price; } Order = new Order { Name = name, StreetAddress = address, City = city, State = state, Zipcode = zip, Price = (decimal)Math.Round(totPrice, 2) }; _context.Order.Add(Order); foreach (Item i in items) { _context.BoughtItem.Add(convertItem(i, Order.ID)); _context.Item.Remove(i); } Response.Cookies.Delete("ddsCookie"); Response.Cookies.Append("ddsCookie", "[]"); await _context.SaveChangesAsync(); return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (!ModelState.IsValid) { return(Page()); } //var itemToUpdate = await _context.Item.FindAsync(id); _context.Attach(Item).State = EntityState.Modified; // Delete Image if (IndexText != null) { urlArray = Directory.GetFiles(Path.Combine(_hostingEnvironment.WebRootPath, Path.Combine("uploads", "ImageFolder_" + Item.FID))); List <string> indexList = IndexText.Split(",").ToList(); DbSet <Image> DbSetCopy = _context.Image; if (indexList.Count != 0) { foreach (var entity in DbSetCopy) { for (int i = 0; i < indexList.Count - 1; i++) { string url = urlArray[int.Parse(indexList[i])]; if (Path.GetFileName(entity.ImageURL).Equals(Path.GetFileName(url))) { _context.Image.Remove(entity); FileInfo f = new FileInfo(@url); f.Delete(); } } } } } // Add Image ArrayList images = new ArrayList(); if (this.AddImage != null) { String uploadFolder = "uploads"; String newDir = "ImageFolder_" + Item.FID; var uploadPath = Path.Combine(_hostingEnvironment.WebRootPath, uploadFolder); var newDirPath = Path.Combine(uploadPath, newDir); foreach (IFormFile f in AddImage) { var fileName = f.FileName; // there needs to be validation on filename var filePath = Path.Combine(newDirPath, fileName); FileStream stream = new FileStream(filePath, FileMode.Create); f.CopyTo(stream); stream.Close(); var filePath2 = Path.Combine(Path.Combine(uploadFolder, newDir), fileName); images.Add(new Image { ImageURL = filePath2 }); } } foreach (Image i in images) { i.ItemID = Item.ID; _context.Image.Add(i); } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ItemExists(Item.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }