Ejemplo n.º 1
0
        public async Task <ActionResult> ConfirmPayment(int?id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Invoice invoice = await db.Invoices.FindAsync(id);

            if (invoice == null)
            {
                return(HttpNotFound());
            }

            invoice.InvoiceStatus   = (InvoiceStatus)2;
            db.Entry(invoice).State = EntityState.Modified;
            await db.SaveChangesAsync();

            InvoicesHub.BroadcastData();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> ConfirmShipment(int?id)
        {
            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 (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Invoice invoice = await db.Invoices.FindAsync(id);

            if (invoice == null)
            {
                return(HttpNotFound());
            }
            invoice.InvoiceStatus   = (InvoiceStatus)1;
            db.Entry(invoice).State = EntityState.Modified;
            await db.SaveChangesAsync();

            InvoicesHub.BroadcastData();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        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"));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            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" }));
            }
            Invoice invoice = await db.Invoices.FindAsync(id);

            db.Invoices.Remove(invoice);
            await db.SaveChangesAsync();

            InvoicesHub.BroadcastData();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Create([Bind(Include = "InvoiceID,OrderID,InvoiceStatus,PaymentDueDate,DateCreated")] Invoice invoice)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }
            if (ModelState.IsValid)
            {
                db.Invoices.Add(invoice);
                await db.SaveChangesAsync();

                InvoicesHub.BroadcastData();
                return(RedirectToAction("Index"));
            }

            ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "UserId", invoice.OrderID);
            return(View(invoice));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> Edit([Bind(Include = "InvoiceID,OrderID,InvoiceStatus,PaymentDueDate,DateCreated,TotalPrice")] Invoice invoice)
        {
            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)
            {
                db.Entry(invoice).State = EntityState.Modified;
                await db.SaveChangesAsync();

                InvoicesHub.BroadcastData();
                return(RedirectToAction("Index"));
            }
            ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "UserId", invoice.OrderID);
            return(View(invoice));
        }