public async Task <ActionResult> Create([Bind(Include = "ProductUnitOfMeasurementID,UnitName,UnitAbbreviation")] ProductUnitOfMeasurement productUnitOfMeasurement) { if (ModelState.IsValid) { db.ProductUnitOfMeasurements.Add(productUnitOfMeasurement); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(productUnitOfMeasurement)); }
public async Task <ActionResult> Create([Bind(Include = "VatCategoryID,VatName,VatPercentage")] VatCategory vatCategory) { if (ModelState.IsValid) { db.VatCategories.Add(vatCategory); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(vatCategory)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,FirstName,MiddleName,LastName,DateofBirth,PersonalPhone,VendorID,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName")] ApplicationUser applicationUser) { if (!User.IsInRole("Administrator")) { return(RedirectToAction("Warning", "Home", new { message = "ACCESS DENIED - Adminstrator Only " })); } if (ModelState.IsValid) { db.Entry(applicationUser).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.VendorID = new SelectList(db.Vendors, "VendorID", "VendorName", applicationUser.VendorID); return(View(applicationUser)); }
public async Task <ActionResult> Edit([Bind(Include = "ProductInOrderID,ProductID,OrderID,Quantity")] ProductInOrder productInOrder) { if (!User.IsInRole("Administrator")) { return(RedirectToAction("Warning", "Home", new { message = "ACCESS DENIED - Restricted to administrator only!" })); } if (ModelState.IsValid) { db.Entry(productInOrder).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "UserId", productInOrder.OrderID); ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", productInOrder.ProductID); return(View(productInOrder)); }
public async Task <ActionResult> Create([Bind(Include = "ProductCategoryID,CategoryName,VatCategoryID")] ProductCategory productCategory) { if (User.IsInRole("Validated User") || User.IsInRole("Unvalidated User")) { return(RedirectToAction("Warning", "Home", new { message = "ACCESS DENIED" })); } if (ModelState.IsValid) { db.ProductCategories.Add(productCategory); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.VatCategoryID = new SelectList(db.VatCategories, "VatCategoryID", "VatName", productCategory.VatCategoryID); return(View(productCategory)); }
public async Task <ActionResult> DeleteConfirmed(int id) { // instead of deleting the product, we change its status to IsInactive Product product = await _context.Products.FindAsync(id); product.IsInactive = true; //_context.Products.Remove(product); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Create([Bind(Include = "ProductID,ProductName,Description,ProductStatus,ProductCategoryID,ProductPrice,ProductUnitOfMeasurementID,UnitsInStock")] Product product) { if (ModelState.IsValid) { if (product.ProductStatus < (ProductStatus)2) { product.ProductStatus = (product.UnitsInStock > 0) ? (ProductStatus)0 : (ProductStatus)1; } db.Products.Add(product); await db.SaveChangesAsync(); ProductsHub.BroadcastData(); return(RedirectToAction("Index")); } ViewBag.ProductCategoryID = new SelectList(db.ProductCategories, "ProductCategoryID", "CategoryName", product.ProductCategoryID); ViewBag.ProductUnitOfMeasurementID = new SelectList(db.ProductUnitOfMeasurements, "ProductUnitOfMeasurementID", "UnitName", product.ProductUnitOfMeasurementID); return(View(product)); }
public async Task <ActionResult> Create([Bind(Include = "OrderID,UserId,DateStarted")] Order order) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (User.IsInRole("Unvalidated User")) { return(RedirectToAction("Warning", "Home", new { message = "ACCESS DENIED - Verify with a vendor first!" })); } if (ModelState.IsValid) { db.Orders.Add(order); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", order.UserId); return(View(order)); }
public async Task <ActionResult> Create([Bind(Include = "VendorID,VendorName,VendorAFM,VendorLegalName,VendorDOI")] Vendor vendor) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (User.IsInRole("Validated User") || User.IsInRole("Unvalidated User")) { return(RedirectToAction("Warning", "Home", new { message = "ACCESS DENIED" })); } if (ModelState.IsValid) { vendor.VendorSecretKey = KeyGenerator.GetUniqueKey(66); db.Vendors.Add(vendor); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(vendor)); }
public async Task <ActionResult> Create(int?orderID) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } Order order = await db.Orders.FindAsync(orderID); if (order == null) { return(HttpNotFound()); } var products = db.ProductInOrders.Where(x => x.OrderID == order.OrderID).Include(x => x.Product.ProductCategory.VatCategory); if (products.Count() == 0) { return(RedirectToAction("Warning", "Home", new { message = "No products added in this order. Click Continue Order to add products." })); } // Check if products are available! if (!UpdateProducts(order)) { return(RedirectToAction("Warning", "Home", new { message = "Not all products are available. Click View Order to see details. " })); } decimal totalPrice = 0; foreach (var item in products) { totalPrice += (item.Product.ProductPrice + Convert.ToDecimal(item.Product.ProductCategory.VatCategory.VatPercentage) * item.Product.ProductPrice / 100.0m) * item.Quantity; } // If products are available, reduce all stocks then complete the rest order.OrderStatus = (OrderStatus)1; Invoice invoice = new Invoice(); invoice.OrderID = (int)orderID; invoice.DateCreated = DateTime.Now; invoice.PaymentDueDate = DateTime.Now.AddMonths(2); invoice.InvoiceStatus = (InvoiceStatus)0; invoice.TotalPrice = totalPrice; db.Invoices.Add(invoice); await db.SaveChangesAsync(); InvoicesHub.BroadcastData(); return(RedirectToAction("Index")); }