public async Task <IActionResult> Create([Bind("ProductId,Name,Price,Description,Active,Slug,CategoryId")] Product product) { if (ModelState.IsValid) { _context.Add(product); var imgFile = Request.Form.Files["image"]; if (imgFile != null || imgFile.Length > 0) { Image img = new Image(); img.Path = imgFile.FileName; var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "img", imgFile.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await imgFile.CopyToAsync(stream); } img.Product = product; _context.Images.Add(img); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryId", product.CategoryId); return(View(product)); }
public async Task <IActionResult> Create([Bind("CategoryId,Name,Slug")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("PaymentMethodId,Name")] PaymentMethod paymentMethod) { if (ModelState.IsValid) { _context.Add(paymentMethod); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(paymentMethod)); }
public async Task <IActionResult> Create([Bind("OrderId,Time,CustomerName,Note,ShipAdress,ContactNumber,PaymentId")] Order order) { if (ModelState.IsValid) { _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PaymentId"] = new SelectList(_context.Payments, "PaymentId", "PaymentId", order.PaymentId); return(View(order)); }
public async Task <IActionResult> Create([Bind("ImageId,Path,ProductId")] Image image) { if (ModelState.IsValid) { _context.Add(image); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductId", image.ProductId); return(View(image)); }