Exemplo n.º 1
0
        public IHttpActionResult SalesLineChart()
        {
            var           customerinvoice = cusinvrepo.GetAll();
            List <string> date            = new List <string>();
            var           fetchdate       = customerinvoice.Select(x => x.OrderDate).Distinct().OrderBy(y => y.Date);

            foreach (var item in fetchdate)
            {
                var i = item.ToString("dd-MM-yyyy");
                date.Add(i);
            }
            List <double> sales = new List <double>();

            foreach (var item in fetchdate)
            {
                var    info  = customerinvoice.Where(x => x.OrderDate == item).ToList();
                double count = 0;
                foreach (var i in info)
                {
                    count = count + i.TotalWithTax;
                }
                sales.Add(Math.Round(count));
            }
            return(Ok(new { date, sales }));
        }
 public ActionResult SalesLineChart()
 {
     if (CheckAccess())
     {
         var           customerinvoice = cusinvrepo.GetAll();
         List <string> date            = new List <string>();
         var           fetchdate       = customerinvoice.Select(x => x.OrderDate).Distinct().OrderBy(y => y.Date);
         foreach (var item in fetchdate)
         {
             var i = item.ToString("dd-MM-yyyy");
             date.Add(i);
         }
         List <double> sales = new List <double>();
         foreach (var item in fetchdate)
         {
             var    info  = customerinvoice.Where(x => x.OrderDate == item).ToList();
             double count = 0;
             foreach (var i in info)
             {
                 count = count + i.TotalWithTax;
             }
             sales.Add(Math.Round(count));
         }
         return(Json(new { date, sales }, JsonRequestBehavior.AllowGet));
     }
     else
     {
         return(RedirectToAction("Login", "Home"));
     }
 }
 public ActionResult Checkout(CustomerInvoice invoice)
 {
     if (CheckIfCustomer())
     {
         if (ModelState.IsValid)
         {
             CheckoutViewModel checkoutDetails = customerrepo.CheckoutDetails();
             invoice.SubTotal         = checkoutDetails.TotalPrice;
             invoice.TotalWithTax     = checkoutDetails.TotalPriceWithTax;
             invoice.CustomerUserName = Session["UserName"].ToString();
             cusinvrepo.Insert(invoice);
             CustomerInvoice lastinvoice = null;
             foreach (var item in cusinvrepo.GetAll())
             {
                 lastinvoice = item;
             }
             foreach (var item in checkoutDetails.CartProductList)
             {
                 CustomerLineItem lineItem = new CustomerLineItem();
                 lineItem.InvoiceId = lastinvoice.InvoiceId;
                 lineItem.ProductId = item.ProductId;
                 lineItem.Quantity  = item.Quantity;
                 lineItem.UnitPrice = item.UnitPrice;
                 lineItem.Total     = item.Quantity * item.UnitPrice;
                 cuslirepo.Insert(lineItem);
                 CompanyProduct product = comprodrepo.GetById(item.ProductId);
                 product.Quantity = product.Quantity - item.Quantity;
                 comprodrepo.Update(product);
             }
             customerrepo.ClearCart();
             return(View("Conformation"));
         }
         else
         {
             TempData["Checkout"] = customerrepo.CheckoutDetails();
             return(View(invoice));
         }
     }
     else
     {
         return(RedirectToAction("Login", "Home"));
     }
 }
 public IHttpActionResult Checkout(CheckoutViewModel checkout)
 {
     if (ModelState.IsValid)
     {
         CustomerInvoice invoice = new CustomerInvoice();
         invoice.OrderDate        = checkout.OrderDate;
         invoice.SubTotal         = checkout.SubTotal;
         invoice.TotalWithTax     = checkout.TotalWithTax;
         invoice.CreditCardType   = checkout.CreditCardType;
         invoice.CardNumber       = checkout.CardNumber;
         invoice.CustomerUserName = checkout.CustomerUserName;
         cusinvrepo.Insert(invoice);
         CustomerInvoice lastinvoice = null;
         foreach (var item in cusinvrepo.GetAll())
         {
             lastinvoice = item;
         }
         foreach (var item in checkout.CartProductList)
         {
             CustomerLineItem lineItem = new CustomerLineItem();
             lineItem.InvoiceId = lastinvoice.InvoiceId;
             lineItem.ProductId = item.ProductId;
             lineItem.Quantity  = item.Quantity;
             lineItem.UnitPrice = item.UnitPrice;
             lineItem.Total     = item.Quantity * item.UnitPrice;
             cuslirepo.Insert(lineItem);
             CompanyProduct product = comprodrepo.GetById(item.ProductId);
             product.Quantity = product.Quantity - item.Quantity;
             comprodrepo.Update(product);
         }
         return(Created("http://localhost:51045/api/customerinvoices" + invoice.InvoiceId, invoice));
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }