public async Task <IActionResult> DeleteConfirmed(int id) { var order = await _context.Orders.SingleOrDefaultAsync(m => m.OrderId == id); _context.Orders.Remove(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("Id,CategroyName")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,HomePhoneNo,MobileNo,Email")] Supplier supplier) { if (ModelState.IsValid) { _context.Add(supplier); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(supplier)); }
public async Task <IActionResult> Create([Bind("Id,CategoryId,SupplierId,ProductName,ProductPrice, Description")] Product product, IFormFile _files) { try { if (ModelState.IsValid) { if (_files != null) { using (var memoryStream = new MemoryStream()) { await _files.CopyToAsync(memoryStream); product.ProductImage = memoryStream.ToArray(); } } else { //string path = AppDomain.CurrentDomain.BaseDirectory + "defaultBook.jpg"; // string path = @"..\wwwroot\images\Temp\defaultBook.jpg"; string path = Environment.CurrentDirectory + @"/wwwroot/images/Temp/defaultBook.jpg"; byte[] image = System.IO.File.ReadAllBytes(path); product.ProductImage = image; } _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException ex) { System.Diagnostics.Debug.WriteLine(ex); //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } PopulateCategoryDropDown(product.CategoryId); PopulateSupplierDropDown(product.SupplierId); return(View(product)); }
public async Task <IActionResult> EnableDisable(string id) { if (id == null) { return(NotFound()); } IEnumerable <ApplicationUser> members = ReturnAllMembers().Result; ApplicationUser member = (ApplicationUser)members.Single(u => u.Id == id); if (member == null) { return(NotFound()); } member.Enabled = !member.Enabled; _context.Update(member); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("Id,CategoryId,SupplierId,ProductName,ProductPrice, Description")] Product product, IFormFile _files) { /* * var relativeName = ""; * var fileName = ""; * * if (_files.Count < 1) * { * relativeName = "/Images/logo.jpg"; * } * else * { * foreach (var file in _files) * { * fileName = ContentDispositionHeaderValue * .Parse(file.ContentDisposition) * .FileName * .Trim('"'); * //Path for localhost * relativeName = "/ProductImages/" + DateTime.Now.ToString("ddMMyyyy-HHmmssffffff") + fileName; * * using (FileStream fs = System.IO.File.Create(_hostingEnv.WebRootPath + relativeName)) * { * await file.CopyToAsync(fs); * fs.Flush(); * } * } * product.ProductImage = relativeName; * } */ try { if (ModelState.IsValid) { if (_files != null) { using (var memoryStream = new MemoryStream()) { await _files.CopyToAsync(memoryStream); product.ProductImage = memoryStream.ToArray(); } } else { //string path = AppDomain.CurrentDomain.BaseDirectory + "defaultBook.jpg"; // string path = @"..\wwwroot\images\Temp\defaultBook.jpg"; string path = Environment.CurrentDirectory + @"/wwwroot/images/Temp/defaultBook.jpg"; byte[] image = System.IO.File.ReadAllBytes(path); product.ProductImage = image; } _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException ex) { System.Diagnostics.Debug.WriteLine(ex); //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } PopulateCategoryDropDown(product.CategoryId); PopulateSupplierDropDown(product.SupplierId); return(View(product)); }