public async Task <IActionResult> Edit(int id, [Bind("Id,Surname,Forename,Email,PermissionsId,Active")] UserAccount userAccount) { if (id != userAccount.Id) { return(NotFound()); } if (userAccount.PermissionsId != 9 && userAccount.PermissionsId != 10) { return(View("IncorrectPermission")); } if (ModelState.IsValid) { try { _context.Update(userAccount); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserAccountExists(userAccount.Id)) { return(NotFound()); } else { throw; } } } UserAccountsDTO user = new UserAccountsDTO { Id = userAccount.Id, Active = userAccount.Active, Email = userAccount.Email, Forename = userAccount.Forename, Surname = userAccount.Surname, PermissionsId = userAccount.PermissionsId }; try { var response = _accounts.PostUserAccount(user); } catch (Exception e) { //_logger.LogWarning(e); } ViewData["PermissionsId"] = new SelectList(_context.Permissions, "Id", "Id", userAccount.PermissionsId); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ProductId,Quantity,Cost,Dispatched,InvoiceId")] Order order) { var invoice = await _context.Invoices.FirstOrDefaultAsync(i => i.Id == order.InvoiceId); if (id != order.Id) { return(NotFound()); } else if (!invoice.Invoiced) { return(View("NotInvoiced")); } order.DispatchDate = DateTime.Now; if (ModelState.IsValid) { try { _context.Update(order); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(order.Id)) { return(NotFound()); } else { throw; } } } OrdersDTO orders = new OrdersDTO { Id = order.Id, Cost = order.Cost, DispatchDate = order.DispatchDate, Dispatched = order.Dispatched, InvoiceId = order.InvoiceId, ProductId = order.ProductId, Quantity = order.Quantity }; try { var response = await _ordersSevice.PushOrder(orders); } catch (Exception e) { //_logger.LogWarning(e); } ViewData["InvoiceId"] = new SelectList(_context.Invoices, "Id", "Id", order.InvoiceId); ViewData["ProductId"] = new SelectList(_context.Products, "id", "Description", order.ProductId); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Rating,Description,Hidden,ProductId,UserAccountId")] Reviews review) { if (id != review.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(review); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReviewExists(review.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ReviewsDTO reviews = new ReviewsDTO { Id = review.Id, Description = review.Description, Hidden = review.Hidden, ProductId = review.ProductId, Rating = review.Rating, UserAccountId = review.UserAccountId }; try { var response = await _reviews.PushReview(reviews); } catch (Exception e) { //_logger.LogWarning(e); } ViewData["UserAccountId"] = new SelectList(_context.UserAccounts, "Id", "Id", review.UserAccountId); ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Id", review.ProductId); return(View(review)); }
public async Task <IActionResult> Edit(int id, [Bind("Id, Invoiced, StaffAccountId, UserAccountId")] Invoice invoice) { if (id != invoice.Id) { return(NotFound()); } //need to alter the staff account to whoever invoiced it if (ModelState.IsValid) { try { _context.Update(invoice); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InvoiceExists(invoice.Id)) { return(NotFound()); } else { throw; } } } InvoicesDTO invoices = new InvoicesDTO { Id = invoice.Id, Invoiced = invoice.Invoiced, StaffAccountId = invoice.StaffAccountId, UserAccountId = invoice.UserAccountId }; try { var response = await _invoicesService.PushInvoices(invoices); } catch (Exception e) { //_logger.LogWarning(e); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> CreateNewPrice(int productId, [Bind("ProductId, Price")] PriceHistory newPrice) { if (productId != newPrice.ProductId) { return(NotFound()); } newPrice.EffectiveFrom = DateTime.Now; if (ModelState.IsValid) { try { _context.Add(newPrice); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(newPrice.ProductId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } PriceHistoriesDTO priceHistories = new PriceHistoriesDTO { Id = newPrice.Id, Price = newPrice.Price, }; try { var response = await _productsService.PushPrice(priceHistories); } catch (Exception e) { //_logger.LogWarning(e); } return(View(newPrice)); }
public async Task <IActionResult> Create([Bind("Id,Name,Quantity")] ProductRequestProductsDTO productRequest) { var product = _productRequestsService.GetProductRequestProducts();//Pull data from api again ProductRequest request = new ProductRequest { Confirmed = false, Quantity = productRequest.Quantity, ProductName = productRequest.Name, Price = product.Result.First(p => p.Name == productRequest.Name).Price }; ProductRequestDTO requestAPI = new ProductRequestDTO { Confirmed = false, Quantity = productRequest.Quantity, ProductName = productRequest.Name, Price = product.Result.First(p => p.Name == productRequest.Name).Price }; if (ModelState.IsValid) { _context.Add(request); await _context.SaveChangesAsync(); } try { var response = _productRequestsService.PushProductRequest(requestAPI); } catch (Exception e) { //_logger.LogWarning(e); } return(RedirectToAction(nameof(Index))); }