public ActionResult Cart() { double?margin = 0; if (Session["SelectedCustomerId"] == null || Session["SelectedCustomerId"].ToString() == "") { TempData["msg"] = "Please select the customer first."; return(RedirectToAction("SelectCustomers")); } else { if (TempData["Margin"] == null) { Session["PromoCode"] = null; margin = GetCustomerMargin(); if (margin == null || margin == 0) { ViewModel.DefaultMargin.DefaultMarginUsers defaultMarginUsers = new ViewModel.DefaultMargin.DefaultMarginUsers(); margin = defaultMarginUsers.GetDefaultMargin().DefaultPercentage; } if (margin == null) { margin = 0; } TempData["Margin"] = margin; Session["Margin"] = margin; } ViewModel.AddToCart.AddToCart cart = new ViewModel.AddToCart.AddToCart(); return(View(cart.Get(0, Session["SelectedCustomerId"].ToString(), true))); } }
//Get invoice for admin public Models.Invoice Get(string CustomerId, int AgentId = 0) { try { Models.Invoice invoice = new Models.Invoice(); //Generate Invoice Number Random random = new Random(); invoice.InvoiceNumber = random.Next(0, 9999999).ToString("D6"); HttpContext.Current.Session["InvoiceNo"] = invoice.InvoiceNumber; //Get Customer information from db ViewModel.PartnerRepository.Customers customers = new ViewModel.PartnerRepository.Customers(ApplicationDomain.Instance); invoice.Customers = customers.GetCustomerById(CustomerId); //If not exist in db then Api will use if (invoice.Customers == null) { invoice.Customers = customers.GetAPICustomerById(CustomerId); } //get cart items ViewModel.AddToCart.AddToCart cart = new ViewModel.AddToCart.AddToCart(); invoice.Cart = cart.Get(AgentId, CustomerId, true); //Get sale tax ViewModel.SaleTax.SaleTax saleTax = new ViewModel.SaleTax.SaleTax(); invoice.SaleTax = saleTax.Get(invoice.Customers.Country, invoice.Customers.Province, AgentId); return(invoice); } catch { return(new Models.Invoice()); } }
public string Buy(int ResellerId, string CustomerId, Int64 InvoiceNo, double DiscountMargin) { string OffersName = string.Empty; using (var db = new ViewModel.Context.ConnectionStringsContext()) using (var dbContextTransaction = db.Database.BeginTransaction()) { try { ViewModel.AddToCart.AddToCart cart = new ViewModel.AddToCart.AddToCart(); List <Models.CartMicrosoftPriceRepo> CartMicrosoftPriceRepo = cart.Get(0, CustomerId, true); //Save the information on sale table Models.Sale sale = new Models.Sale { CustomerId = CustomerId, InvoiceNo = InvoiceNo, ResellerId = ResellerId, SaleDate = DateTime.Now, DiscountMargin = DiscountMargin }; db.Sale.Add(sale); db.SaveChanges(); //Save the items in db foreach (var item in CartMicrosoftPriceRepo) { ViewModel.Subscription.Subscriptions subscriptions = new Subscription.Subscriptions(ApplicationDomain.Instance); OffersName += item.Name + ", "; Microsoft.Store.PartnerCenter.Models.Orders.Order order = subscriptions.PlaceOrder(CustomerId, item.MicrosoftId, item.License, Models.PurchaseUnit.Months, item.Name); Models.SaleItems saleItems = new Models.SaleItems { License = item.License, OfferId = item.MicrosoftId, OriginalPrice = (double)System.Math.Round(item.ERPrice, 2), SaleId = sale.Id, DiscountPrice = (double)System.Math.Round(item.ERPrice - (item.ERPrice * DiscountMargin) / 100, 2), PurchaseUnitNumber = 0, PurchaseUnit = 0, OrderId = order.Id, }; db.SaleItems.Add(saleItems); db.SaveChanges(); } // If items are sale then remove that items from cart db.Cart.Where(m => m.AgentId == ResellerId && m.Status == true).ToList().ForEach(c => c.Status = false); db.SaveChanges(); dbContextTransaction.Commit(); //Send email to customer SendEmailOffer(OffersName, CustomerId); return("Successfully Items has been purchased"); } catch { dbContextTransaction.Rollback(); return("Unknown error occur, Please try again."); } } }
public JsonResult UpdateItem(int Id, int License, string BillingFrequency) { ViewModel.AddToCart.AddToCart addToCart = new ViewModel.AddToCart.AddToCart(); return(Json(addToCart.UpdateById(Id, License, BillingFrequency), JsonRequestBehavior.AllowGet)); }
public ActionResult DeleteAll() { ViewModel.AddToCart.AddToCart cart = new ViewModel.AddToCart.AddToCart(); cart.DeleteAll(0); return(RedirectToAction("PickMicrosoftOffers")); }
public JsonResult DeleteItem(int Id) { ViewModel.AddToCart.AddToCart cart = new ViewModel.AddToCart.AddToCart(); return(Json(cart.Delete(Id, 0), JsonRequestBehavior.AllowGet)); }
//public ActionResult Users(string Id) //{ // ViewModel.Users.Users users = new ViewModel.Users.Users(ApplicationDomain.UserInstance); // //IEnumerable<Microsoft.Store.PartnerCenter.Models.Customers.Customer> obj = // users.Get(Id); // return View(); //} #endregion #region Cart public JsonResult AddToCart(string Id, int License) { ViewModel.AddToCart.AddToCart cart = new ViewModel.AddToCart.AddToCart(); return(Json(cart.Save(Id, License, 0, Session["SelectedCustomerId"].ToString()), JsonRequestBehavior.AllowGet)); // the 0 mean it's a Admin }