public IActionResult AddBasket(string ID) { try { var tempProduct = ListProduct.Find(x => x._id == ID); tbl_Basket _basket = new tbl_Basket { _id = tempProduct._id, BookAuthor = tempProduct.BookAuthor, BookCategory = tempProduct.BookCategory, BookName = tempProduct.BookName, BookPrice = tempProduct.BookPrice }; _unitOfWork.Baskets.Insert(_basket); _unitOfWork.Save(); var status = new { operation = "Success" }; return(Content(JsonConvert.SerializeObject(status), "application/json")); } catch (Exception e) { throw; } return(View()); }
public static decimal GetDeliveryTaxAmount(this tbl_Basket table) { if (table.tbl_Postage != null && table.tbl_BasketContent.Count > 0) { decimal maxTax = table.tbl_BasketContent.Max(bc => bc.GetTaxValue()); Tuple <decimal, decimal> postagePriceAndTax = PriceManager.GetPostagePriceAndTax(table.tbl_Postage, maxTax, table.B_DomainID); return(postagePriceAndTax.Item2); } return(0); }
public static string GetDeliveryTaxAmountString(this tbl_Basket table, bool hideTax = false) { if (table.tbl_Postage != null && table.tbl_BasketContent.Count > 0) { decimal maxTax = table.tbl_BasketContent.Max(bc => bc.GetTaxValue()); Tuple <decimal, decimal> postagePriceAndTax = PriceManager.GetPostagePriceAndTax(table.tbl_Postage, maxTax, table.B_DomainID); return(String.Format("{0:C}", postagePriceAndTax.Item2)); } return(String.Empty); }
public static decimal GetDiscountAmount(this tbl_Basket table) { if (table.tbl_Discount != null) { decimal totalPrice = 0, totalTaxAmount = 0; foreach (var content in table.tbl_BasketContent) { Tuple <decimal, decimal> priceAndTax = PriceManager.GetPriceAndTaxAmounts(content.tbl_ProductPrice, content.BC_Quantity); totalPrice += priceAndTax.Item1; totalTaxAmount += priceAndTax.Item2; } return(PriceManager.GetDiscountAmount(table.tbl_Discount, totalPrice, totalTaxAmount, table.B_DomainID)); } return(0); }
public static decimal GetProductsPrice(this tbl_Basket table, bool?includeTax = null) { IDomain domainService = (IDomain)DependencyResolver.Current.GetService <IDomain>(); var priceIncludesTax = domainService.GetSettingsValueAsBool(SettingsKey.priceDisplayIncludesVAT, table.B_DomainID); Tuple <decimal, decimal> priceAndTax = GetBasketPriceAndTax(table, true); if (includeTax.HasValue) { if (includeTax.Value) { return(priceIncludesTax ? priceAndTax.Item1 : priceAndTax.Item1 + priceAndTax.Item2); } return(priceIncludesTax ? priceAndTax.Item1 - priceAndTax.Item2 : priceAndTax.Item2); } return(priceAndTax.Item1); }
public IActionResult DeleteProduct(string ID) { try { var t = _unitOfWork.Products.Find(x => x._id == ID); tbl_Products del = new tbl_Products { _id = t._id, BookAuthor = t.BookAuthor, BookCategory = t.BookCategory, BookName = t.BookName, BookPrice = t.BookPrice, }; tbl_Basket dell = new tbl_Basket { _id = t._id, BookAuthor = t.BookAuthor, BookCategory = t.BookCategory, BookName = t.BookName, BookPrice = t.BookPrice, }; _unitOfWork.Products.Delete(del); _unitOfWork.Baskets.Delete(dell); _unitOfWork.Save(); var status = new { operation = "Success" }; return(Content(JsonConvert.SerializeObject(status), "application/json")); } catch (Exception) { var status = new { operation = "Wrong" }; return(Content(JsonConvert.SerializeObject(status), "application/json")); } return(View()); }
public void CopyValuesFromBasket(tbl_Basket basket) { if (basket != null) { this.Basket = basket; this.BasketID = basket.BasketID; this.IsDeliverable = basket.IsDeliverable; Email = basket.B_CustomerEMail; BillingAddressTheSame = basket.B_BillingEqDelivery; Instructions = basket.B_DeliveryNotes; DeliveryTitle = basket.B_DeliveryTitle; DeliveryFirstName = basket.B_DeliveryFirstnames; DeliverySurname = basket.B_DeliverySurname; DeliveryPhone = basket.B_DeliveryPhone; DeliveryAddress1 = basket.B_DeliveryAddress1; DeliveryAddress2 = basket.B_DeliveryAddress2; DeliveryAddress3 = basket.B_DeliveryAddress3; DeliveryCity = basket.B_DeliveryCity; DeliveryPostcode = basket.B_DeliveryPostCode; DeliveryState = basket.B_DeliveryState; DeliveryCountry = basket.B_DeliveryCountry; DeliveryCountryID = basket.B_DeliveryCountryID.GetValueOrDefault(0); BillingTitle = basket.B_BillingTitle; BillingFirstName = basket.B_BillingFirstnames; BillingSurname = basket.B_BillingSurname; BillingPhone = basket.B_BillingPhone; BillingAddress1 = basket.B_BillingAddress1; BillingAddress2 = basket.B_BillingAddress2; BillingAddress3 = basket.B_BillingAddress3; BillingCity = basket.B_BillingCity; BillingPostcode = basket.B_BillingPostCode; BillingState = basket.B_BillingState; BillingCountry = basket.B_BillingCountry; BillingCountryID = basket.B_BillingCountryID; } }
private static Tuple <decimal, decimal> GetBasketPriceAndTax(tbl_Basket table, bool onlyProductsPrice = false) { if (table == null || table.tbl_BasketContent.Count == 0) { return(new Tuple <decimal, decimal>(0, 0)); } decimal totalPrice = 0, totalTaxAmount = 0; foreach (var content in table.tbl_BasketContent) { Tuple <decimal, decimal> priceAndTax = PriceManager.GetPriceAndTaxAmounts(content.tbl_ProductPrice, content.BC_Quantity); totalPrice += priceAndTax.Item1; totalTaxAmount += priceAndTax.Item2; } if (onlyProductsPrice) { return(new Tuple <decimal, decimal>(totalPrice, totalTaxAmount)); } if (table.tbl_Discount != null) { Tuple <decimal, decimal> priceAndTax = PriceManager.AddDiscountToPrice(table.tbl_Discount, totalPrice, totalTaxAmount, table.B_DomainID); totalPrice = priceAndTax.Item1; totalTaxAmount = priceAndTax.Item2; } if (table.tbl_Postage != null) { decimal maxTax = table.tbl_BasketContent.Max(bc => bc.GetTaxValue()); Tuple <decimal, decimal> postagePriceAndTax = PriceManager.GetPostagePriceAndTax(table.tbl_Postage, maxTax, table.B_DomainID); totalPrice += postagePriceAndTax.Item1; totalTaxAmount += postagePriceAndTax.Item2; } return(new Tuple <decimal, decimal>(totalPrice, totalTaxAmount)); }
public static decimal GetDeliveryAmount(this tbl_Basket table, bool?includeTax = null) { if (table.tbl_Postage != null && table.tbl_BasketContent.Count > 0) { IDomain domainService = (IDomain)DependencyResolver.Current.GetService <IDomain>(); var priceIncludesTax = domainService.GetSettingsValueAsBool(SettingsKey.priceDisplayIncludesVAT, table.B_DomainID); decimal maxTax = table.tbl_BasketContent.Max(bc => bc.GetTaxValue()); Tuple <decimal, decimal> postagePriceAndTax = PriceManager.GetPostagePriceAndTax(table.tbl_Postage, maxTax, table.B_DomainID); if (includeTax.HasValue) { if (includeTax.Value) { return(priceIncludesTax ? postagePriceAndTax.Item1 : postagePriceAndTax.Item1 + postagePriceAndTax.Item2); } return(priceIncludesTax ? postagePriceAndTax.Item1 - postagePriceAndTax.Item2 : postagePriceAndTax.Item1); } return(postagePriceAndTax.Item1); } return(0); }
protected tbl_Basket FindBasket() { tbl_Basket basket = null; if (CookieManager.BasketCookie.HasValue) { basket = ECommerceService.GetBasketByID(CookieManager.BasketCookie.Value); if (basket == null) { return(null); } int customerID = basket.B_CustomerID ?? 0; if (AdminUser != null && !AdminUser.IsAdmn && customerID != AdminUser.UserID) { basket = ECommerceService.UpdateBasketCustomerID(AdminUser.UserID, basket.BasketID); } else if ((AdminUser == null && customerID > 0) || (AdminUser != null && AdminUser.IsAdmn && customerID > 0)) { basket = ECommerceService.UpdateBasketCustomerID(0, basket.BasketID); } } else if (Request.IsAuthenticated && !AdminUser.IsAdmn) { var customer = UserService.GetCustomerByID(this.AdminUser.UserID); if (customer != null) { basket = customer.tbl_Basket.OrderByDescending(c => c.B_LastAccessed).FirstOrDefault(); if (basket != null) { CookieManager.BasketCookie = basket.BasketID; } } } return(basket); }
public CheckoutModel(tbl_Basket basket) { this.IsCheckoutStep = true; this.CopyValuesFromBasket(basket); }
public static decimal GetWeight(this tbl_Basket table) { return(table.tbl_BasketContent.Sum(bc => bc.tbl_ProductPrice.PR_Weight.GetValueOrDefault(0))); }
public static string GetDiscountAmountString(this tbl_Basket table) { return(String.Format("{0:C}", table.GetDiscountAmount())); }
public static string GetTaxAmountString(this tbl_Basket table) { Tuple <decimal, decimal> priceAndTax = GetBasketPriceAndTax(table); return(String.Format("{0:C}", priceAndTax.Item2)); }
public static decimal GetTaxAmount(this tbl_Basket table) { Tuple <decimal, decimal> priceAndTax = GetBasketPriceAndTax(table); return(priceAndTax.Item2); }
public static string GetProductsPriceString(this tbl_Basket table, bool hideTax = false) { Tuple <decimal, decimal> priceAndTax = GetBasketPriceAndTax(table, true); return(PriceManager.FormatPrice(priceAndTax.Item1, priceAndTax.Item2, table.B_DomainID, hideTax)); }