public ViewResult Index(int? page) { CurrencyConvertYahooController rateController = new CurrencyConvertYahooController(); _rate = rateController.ConvertCurrency("AUD", "CNY", 1); var productsVM = new List<CoffeeInvoice.Models.ViewModel.ProductViewModel>(); if (Session["LoginUser"] != null) { User user = (User)Session["LoginUser"]; var products = db.Products.OrderBy(i => i.ProductName).Include("Provider").ToList(); products = products.Where(x => x.UserID == user.UserID).ToList(); foreach (var pro in products) { CoffeeInvoice.Models.ViewModel.ProductViewModel proVM = new Models.ViewModel.ProductViewModel(); proVM.ProductID = pro.ProductID; proVM.ProductName = pro.ProductName; proVM.Provider = pro.Provider; proVM.ProviderID = pro.ProviderID; proVM.Price = pro.Price; proVM.CNYSellPrice = pro.CNYSellPrice; proVM.CNYPrice = pro.Price * AUDCNYRate; proVM.UserID = pro.UserID; if (db.PurchaseProducts.Where(x => x.ProductID == pro.ProductID).Count() > 0) { proVM.IsProductPurchased = true; } else proVM.IsProductPurchased = false; productsVM.Add(proVM); } } int currentPageIndex = page.HasValue ? page.Value - 1 : 0; var productsListPaged = productsVM.ToPagedList(currentPageIndex, defaultPageSize); return View(productsListPaged); }
public JsonResult GetTransportPrice(decimal Weight) { if (Session["LoginUser"] != null) { int userid = ((User)Session["LoginUser"]).UserID; SystemConstants weightrate = db.SystemConstants.Where(x => x.UserID == userid).First(); if (weightrate != null) { decimal transportUnit = weightrate.ConstrantValue; CurrencyConvertYahooController rateController = new CurrencyConvertYahooController(); decimal rate = rateController.ConvertCurrency("AUD", "CNY", 1); var value = new { TransportPrice = Decimal.Round(transportUnit * Weight * rate, 2, MidpointRounding.AwayFromZero) }; return Json(value, JsonRequestBehavior.AllowGet); } } var data = new { TransportPrice = 0 }; return Json(data, JsonRequestBehavior.AllowGet); }
public ActionResult Edit(int id) { Product product = db.Products.Find(id); CurrencyConvertYahooController rateController = new CurrencyConvertYahooController(); _rate = rateController.ConvertCurrency("AUD", "CNY", 1); if (!product.CNYPrice.HasValue) { if (product.Price > 0) product.CNYPrice = product.Price * AUDCNYRate; } if (Session["LoginUser"] != null) { User user = (User)Session["LoginUser"]; ViewBag.ProviderID = new SelectList(db.Providers.Where(x => x.UserID == user.UserID).OrderBy(x => x.Name), "ProviderID", "Name", product.ProviderID); } return View(product); }
public ActionResult Edit(int id) { CurrencyConvertYahooController rateController = new CurrencyConvertYahooController(); _rate = rateController.ConvertCurrency("AUD", "CNY", 1); Transaction t = db.Transactions.Find(id); TransactionModel tm = new TransactionModel(); tm.Customer = t.Customer; tm.CustomerID = t.CustomerID; tm.Number = t.Number; tm.Product = t.Product; tm.ProductID = t.ProductID; tm.TimeStamp = t.TimeStamp; tm.TransactionID = t.TransactionID; tm.User = t.User; tm.UserID = t.UserID; tm.IsPaid = t.IsPaid; tm.PaidDateTime = t.PaidDateTime; tm.CNYPrice = t.CNYPrice; tm.CNYSellPrice = t.CNYSellPrice; tm.Price = t.Price; tm.Weight = t.Weight; if (Session["LoginUser"] != null) { User user = (User)Session["LoginUser"]; tm.TransportCharge = (tm.Weight * db.SystemConstants.Where(x => x.UserID == user.UserID).Select(x => x.ConstrantValue).First() * AUDCNYRate).ToString(); } if (t.Number > 0) { tm.TransactionSellAmount = (t.Number * t.CNYSellPrice).ToString(); } ViewBag.Products = new SelectList(db.Products.OrderByDescending(x => x.ProductName), "ProductID", "ProductName", t.ProductID); ViewBag.Customers = new SelectList(db.Customers.OrderByDescending(x => x.Name), "CustomerID", "Name", t.CustomerID); return View(tm); }