public async Task <IActionResult> Edit(string id, [Bind("OrderId,HasBeenPlaced,ClientId")] Order order) { if (id != order.OrderId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(order); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(order.OrderId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ClientId"] = new SelectList(_context.User, "Id", "Id", order.ClientId); return(View(order)); }
public async Task <IActionResult> Edit(string id, [Bind("ProductId,ProductName,ProductDescription,Price,ProductPicture,Sales,SpecificationFile")] Product product) { if (id != product.ProductId) { return(NotFound()); } product.Nprice = (product.Price - (15 * product.Price / 100)); if (ModelState.IsValid) { try { _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.ProductId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,Name,Address,CardNumber,RoleId")] User user) { if (id != user.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["RoleId"] = new SelectList(_context.Role, "RoleId", "Role1", user.RoleId); return(View(user)); }
public async Task <IActionResult> Edit(string id, [Bind("OrderIdFk,ProductIdFk,IdProductOrder")] ProductOrder productOrder) { if (id != productOrder.IdProductOrder) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(productOrder); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductOrderExists(productOrder.IdProductOrder)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["OrderIdFk"] = new SelectList(_context.Order, "OrderId", "OrderId", productOrder.OrderIdFk); ViewData["ProductIdFk"] = new SelectList(_context.Product, "ProductId", "ProductId", productOrder.ProductIdFk); return(View(productOrder)); }
public async Task <IActionResult> Edit(int id, [Bind("ParentCategoryID,Name,Description,PictureID,isFeatured,ID,IsActive,IsDeleted,ModifiedOn")] Category category) { if (id != category.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(category.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ParentCategoryID"] = new SelectList(_context.Categories, "ID", "ID", category.ParentCategoryID); ViewData["PictureID"] = new SelectList(_context.Pictures, "ID", "ID", category.PictureID); return(View(category)); }
public async Task <IActionResult> Edit(int id, [Bind("CategoryID,Name,Price,Description,Discount,isFeatured,ThumbnailPictureID,SKU,Tags,Barcode,Supplier,ID,IsActive,IsDeleted,ModifiedOn")] Product product) { if (id != product.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "Name", product.CategoryID); return(View(product)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Titulo,Autor,Editora,Preco")] Livros livros) { if (id != livros.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(livros); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LivrosExists(livros.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(livros)); }
public async Task <IActionResult> Edit(int id, [Bind("RoleId,Role1")] Role role) { if (id != role.RoleId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(role); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RoleExists(role.RoleId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(role)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Price")] Food food) { if (id != food.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(food); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FoodExists(food.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(food)); }
public async Task <IActionResult> Detail(int?id) { BlogViewModel vm = new BlogViewModel() { Blog = _blogService.GetBlogByID(id.Value), Products = _productService.GetProductsByView(), Categories = _categoryService.GetCategories() }; if (id == null) { return(View("Error")); } string key = Convert.ToString(id); string value = "K101"; var cookieValue = Request.Cookies[key]; if (cookieValue == null) { CookieOptions cookieOptions = new CookieOptions(); cookieOptions.Expires = DateTime.Now.AddDays(1); Response.Cookies.Append(key, value, cookieOptions); vm.Blog.Hit += 1; } _context.Update(vm.Blog); await _context.SaveChangesAsync(); return(View(vm)); }
public async Task <IActionResult> Edit(string id, [Bind("ProductId,CategoryId,IdProductCategory")] ProductCategory productCategory) { if (id != productCategory.IdProductCategory) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(productCategory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductCategoryExists(productCategory.IdProductCategory)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Category, "CategoryId", "CategoryName", productCategory.CategoryId); ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "ProductName", productCategory.ProductId); return(View(productCategory)); }
public async Task <IActionResult> Edit(string id, [Bind("CategoryId,CategoryName")] Category category) { if (id != category.CategoryId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(category.CategoryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Edit(int id, [Bind("Name,Url,Click,EndTime,ID,IsActive,IsDeleted,ModifiedOn")] Advertisement advertisement) { if (id != advertisement.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(advertisement); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdvertisementExists(advertisement.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(advertisement)); }
public async Task <IActionResult> Edit(string id, [Bind("StockId,ProductId,RemainingStock")] StockEntry stockEntry) { if (id != stockEntry.StockId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(stockEntry); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StockEntryExists(stockEntry.StockId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "ProductName", stockEntry.ProductId); return(View(stockEntry)); }
public async Task BaixaEstoque(int id, int quantidade) { var produtoCor = await _context.ProdutosCorModel.FirstOrDefaultAsync(x => x.Id == id); var newEstoque = produtoCor.Estoque + quantidade; produtoCor.SetEstoque(newEstoque); _context.Update(produtoCor); //await _context.SaveChangesAsync(); }
public async Task <IActionResult> Edit(int id, [Bind("CategoryID,ProductName,Description,Seller,Number,Publishing,Author,Pages,Price,Discount,Cost,isFeatured,ThumbnailPictureID,SKU,Tags,Barcode,Supplier,ID,IsActive,IsDeleted,ModifiedOn")] Product product, IFormFile Tags, string EditPhoto) { string userId = _userManager.GetUserId(HttpContext.User); if (id != product.ID) { return(NotFound()); } if (Tags == null) { product.Tags = EditPhoto; } else { string path = "/Uploads/" + Guid.NewGuid() + Tags.FileName; using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create)) { Path.Combine(Directory.GetCurrentDirectory(), "Uploads", path); await Tags.CopyToAsync(fileStream); } product.Tags = path.Remove(0, 8); } if (ModelState.IsValid) { product.Seller = userId; try { _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "Name", product.CategoryID); return(View(product)); }
public async Task <IActionResult> Edit(int id, [Bind("PostName,PostUrl,PhotoUrl,Hit,UserID,UserName,PostDate,MyProperty,ID,IsActive,IsDeleted,ModifiedOn,Description")] Blog blog, IFormFile PhotoUrl, string EditPhoto) { string userId = _userManager.GetUserId(HttpContext.User); string userName = _userManager.GetUserName(HttpContext.User); if (id != blog.ID) { return(NotFound()); } if (PhotoUrl == null) { blog.PhotoUrl = EditPhoto; } else { string path = "/Uploads/" + Guid.NewGuid() + PhotoUrl.FileName; using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create)) { Path.Combine(Directory.GetCurrentDirectory(), "Uploads", path); await PhotoUrl.CopyToAsync(fileStream); } blog.PhotoUrl = path.Remove(0, 8); } if (ModelState.IsValid) { blog.UserID = userId; blog.UserName = userName; try { _context.Update(blog); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BlogExists(blog.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(blog)); }
public async Task <IActionResult> Edit(int?id, bool IsActive) { if (id == null) { return(View("Error")); } BlogViewModel vm = new BlogViewModel(); vm.Blog = _blogService.GetBlogByID(id.Value); vm.Blog.IsActive = IsActive; _context.Update(vm.Blog); await _context.SaveChangesAsync(); return(RedirectToAction("index", "home")); }
public async Task <ActionResult <Pedido> > PostPedido(PedidoViewModel pedido) { _context.cliente.Add(pedido.cliente); await _context.SaveChangesAsync(); var cliente = _context.cliente.OrderByDescending(c => c.id).FirstOrDefault(); Pedido Pedido = new Pedido(); Pedido.clienteId = cliente.id; Pedido.dataPedido = DateTime.Now.ToString(); _context.pedido.Add(Pedido); await _context.SaveChangesAsync(); var p = _context.pedido.OrderByDescending(x => x.id).FirstOrDefault(); foreach (ItemViewModel elemento in pedido.itens) { Item item = new Item(); var estoque = elemento.produto.estoque - elemento.quantidade; if (estoque < 0) { return(NotFound()); } elemento.produto.estoque = estoque; item.produtoId = elemento.produto.id; item.pedidoId = p.id; item.quantidade = elemento.quantidade; _context.Update(elemento.produto); _context.item.Add(item); await _context.SaveChangesAsync(); } return(CreatedAtAction("GetPedido", new { id = Pedido.id }, Pedido)); }
public async Task <IActionResult> Edit(int?id, bool IsDeleted, bool IsActive) { if (id == null) { return(View("Error")); } ProductViewModel product = new ProductViewModel(); product.Product = _productService.GetProductByID(id.Value); product.Product.IsDeleted = IsDeleted; product.Product.IsActive = IsActive; _context.Update(product.Product); await _context.SaveChangesAsync(); return(RedirectToAction("index", "products")); }
public async Task <IActionResult> Detail(int?id) { if (id == null) { return(View("Error")); } ProductViewModel vm = new ProductViewModel(); string key = Convert.ToString(id); string value = "K101"; vm.Product = _productService.GetProductByID(id.Value); var cookieValue = Request.Cookies[key]; if (cookieValue == null) { CookieOptions cookieOptions = new CookieOptions(); cookieOptions.Expires = DateTime.Now.AddDays(1); Response.Cookies.Append(key, value, cookieOptions); if (vm.Product.Hit != null) { vm.Product.Hit += 1; } else { vm.Product.Hit = 1; } } _context.Update(vm.Product); await _context.SaveChangesAsync(); return(View(vm)); }