public JsonResult AddItemToCart(int ID, int Quantity) { if (CookieStore.GetCookie(cookiekey).Contains(ID.ToString())) { return(Json(new { Added = 2 }, JsonRequestBehavior.AllowGet)); } else { string cookievalue = ID + ":" + Quantity; TimeSpan cookieexpire = new TimeSpan(1000, 0, 0, 0); CookieStore.SetCookie(cookiekey, cookievalue, cookieexpire); return(Json(new { Added = 1 }, JsonRequestBehavior.AllowGet)); } }
public ActionResult AddToCompareList(int productid, int size = 0, string attributes = "") { var currentUserId = Convert.ToInt32(GlobalUser.getGlobalUser().UserId); var productSize = _productSizeBusiness.GetListWT(c => c.ProductId == productid).FirstOrDefault(); var defaultSize = productSize == null ? 0 : productSize.Id; if (size == 0) { size = defaultSize; } if (currentUserId > 0) { var count = _CompareListBusiness.GetListWT(c => c.UserId == currentUserId && c.ProductId == productid).Count(); if (count <= 0) { CompareList compareList = new CompareList(); compareList.ProductId = productid; compareList.UserId = currentUserId; _CompareListBusiness.Insert(compareList); _unitOfWork.SaveChanges(); } } else { CookieStore mycookie = new CookieStore(); var products = mycookie.GetCookie(Enumerator.CustomerAction.CompareList.ToString()); var value = string.Empty; if (string.IsNullOrEmpty(products)) { value = productid.ToString() + "~" + size.ToString() + "~" + attributes.ToString(); } else { if (!products.Split(',').Select(c => c.Split('~')[0]).Contains(productid.ToString())) { value = products + "," + productid.ToString() + "~" + size.ToString() + "~" + attributes.ToString(); } } var expireCookieTimeHr = Convert.ToInt32(ReadConfigData.GetAppSettingsValue("ExpireCookieTimeHr")); mycookie.SetCookie(Enumerator.CustomerAction.CompareList.ToString(), value, expireCookieTimeHr); } return(new EmptyResult()); }
public ActionResult ProductAddToCart(int productid, int quantity, int size = 0, string attributes = "") { var currentUserId = Convert.ToInt32(GlobalUser.getGlobalUser().UserId); var productSize = _productSizeBusiness.GetListWT(c => c.ProductId == productid).FirstOrDefault(); var defaultSize = productSize == null ? 0 : productSize.Id; if (size == 0) { size = defaultSize; } if (currentUserId > 0) { var cartList = _AddToCartBusiness.GetListWT(c => c.UserId == currentUserId && c.ProductId == productid); AddToCart addToCart = new AddToCart(); addToCart.ProductId = productid; addToCart.UserId = currentUserId; addToCart.Quantity = quantity; addToCart.Size = size; addToCart.Attributes = attributes; if (cartList.Count() <= 0) { _AddToCartBusiness.Insert(addToCart); } else { addToCart.ID = cartList.FirstOrDefault().ID; _AddToCartBusiness.Update(addToCart); } _unitOfWork.SaveChanges(); } else { CookieStore mycookie = new CookieStore(); var products = mycookie.GetCookie(Enumerator.CustomerAction.AddToCart.ToString()); var newValue = productid.ToString() + "~" + quantity.ToString() + "~" + size.ToString() + "~" + attributes.ToString(); var value = mycookie.FormatCartCookieValue(products, newValue); var expireCookieTimeHr = Convert.ToInt32(ReadConfigData.GetAppSettingsValue("ExpireCookieTimeHr")); mycookie.SetCookie(Enumerator.CustomerAction.AddToCart.ToString(), value, expireCookieTimeHr); } return(new EmptyResult()); }
public void clearCart() { var currentUserId = Convert.ToInt32(GlobalUser.getGlobalUser().UserId); if (currentUserId > 0) { var cartData = _AddToCartBusiness.GetList(c => c.UserId == currentUserId); foreach (var product in cartData) { _AddToCartBusiness.Delete(product); _unitOfWork.SaveChanges(); } } else { CookieStore mycookie = new CookieStore(); var expireCookieTimeHr = Convert.ToInt32(ReadConfigData.GetAppSettingsValue("ExpireCookieTimeHr")); mycookie.SetCookie(Enumerator.CustomerAction.AddToCart.ToString(), "", expireCookieTimeHr); } }
public ActionResult DeleteFromCompareList(int productid) { var currentUserId = Convert.ToInt32(GlobalUser.getGlobalUser().UserId); if (currentUserId > 0) { var compareListProduct = _CompareListBusiness.GetList(c => c.UserId == currentUserId && c.ProductId == productid).FirstOrDefault(); if (compareListProduct != null) { _CompareListBusiness.Delete(compareListProduct); _unitOfWork.SaveChanges(); } } else { CookieStore mycookie = new CookieStore(); var products = mycookie.GetCookie(Enumerator.CustomerAction.CompareList.ToString()); var newCookieValueString = string.Empty; foreach (var prdId in products.Split(',')) { if (prdId.Split('~')[0] != productid.ToString()) { newCookieValueString = newCookieValueString + "," + prdId; } } var value = string.Empty; if (!string.IsNullOrEmpty(newCookieValueString)) { value = newCookieValueString.Substring(1); } var expireCookieTimeHr = Convert.ToInt32(ReadConfigData.GetAppSettingsValue("ExpireCookieTimeHr")); mycookie.SetCookie(Enumerator.CustomerAction.CompareList.ToString(), value, expireCookieTimeHr); } return(new EmptyResult()); }
public ActionResult DeleteFromCartList(int productid) { var currentUserId = Convert.ToInt32(GlobalUser.getGlobalUser().UserId); if (currentUserId > 0) { var cartProduct = _AddToCartBusiness.GetList(c => c.UserId == currentUserId && c.ProductId == productid).FirstOrDefault(); if (cartProduct != null) { _AddToCartBusiness.Delete(cartProduct); _unitOfWork.SaveChanges(); } } else { CookieStore mycookie = new CookieStore(); var products = mycookie.GetCookie(Enumerator.CustomerAction.AddToCart.ToString()); var productId = productid.ToString(); var value = mycookie.FormatCartCookieValueAfterDelete(products, productId); var expireCookieTimeHr = Convert.ToInt32(ReadConfigData.GetAppSettingsValue("ExpireCookieTimeHr")); mycookie.SetCookie(Enumerator.CustomerAction.AddToCart.ToString(), value, expireCookieTimeHr); } return(new EmptyResult()); }
public string SaveOrder(string paymentid) { var ordertoken = string.Empty; var checkOutViewModel = (CheckOutViewModel)Session["CheckOutViewModel"]; _unitOfWork.BeginTransaction(); try { var productList = _productBusiness.GetListWT(); OrderDetail order = new OrderDetail(); order.TokenKey = GlobalMethods.GetToken(); order.FirstName = checkOutViewModel.FirstNameShopper; order.LastName = checkOutViewModel.LastNameShopper; order.Email = checkOutViewModel.EmailShopper; order.Phone = checkOutViewModel.PhoneShopper; //order.MobilePhone = checkOutViewModel.MobilePhoneShopper; //order.Address = checkOutViewModel.AddressShopper; //order.Pincode = checkOutViewModel.PincodeShopper; //order.City = checkOutViewModel.CityShopper; order.PaymentType = checkOutViewModel.PaymentType; order.PaymentId = paymentid; //order.ShippingOrder = checkOutViewModel.ShippingOrder; order.OrderedBy = "Guest"; order.OrderStatus = "New"; order.OrderDate = DateTime.Now; order.OrderCode = ""; _OrderBusiness.Insert(order); _unitOfWork.SaveChanges(); order.OrderCode = "OC" + order.OrderId; _OrderBusiness.Update(order); _unitOfWork.SaveChanges(); ordertoken = order.TokenKey; //generating message var smsmessage = "Thank you for your purchase. " + Environment.NewLine + "Your order code is:" + order.OrderCode + Environment.NewLine; var mailmessage = "Thank you for placing an order.<br>Your Order detail:<br>"; mailmessage = mailmessage + "Order Code:" + order.OrderCode + "<br>"; mailmessage = mailmessage + "Order Date:" + order.OrderDate.ToShortDateString() + "<br>"; mailmessage = mailmessage + "Payment:" + order.PaymentType + "<br>"; var itemdetailmessage = string.Empty; //Adding Order Decimal totalAmount = 0; OrderedItem ordItem = new OrderedItem(); if (!string.IsNullOrEmpty(checkOutViewModel.OrderListJson)) { dynamic Obj = Newtonsoft.Json.JsonConvert.DeserializeObject(checkOutViewModel.OrderListJson); foreach (var product in Obj) { var productId = Convert.ToInt32(product.ProductID.ToString()); var sizeId = Convert.ToInt32(product.SizeId.ToString()); var attributes = product.AttributeId.ToString(); var prdt = productList.Where(c => c.ProductID == productId).FirstOrDefault(); ordItem.OrderId = Convert.ToInt32(order.OrderId); ordItem.ProductId = productId; ordItem.OrderQuantity = product.Quantity; ordItem.ProductName = prdt.ProductName; ordItem.Price = _productBusiness.GetSelectedPrice(productId, sizeId, attributes); ordItem.DiscountPercent = prdt.DiscountPercent; ordItem.Size = Convert.ToInt32(product.SizeId); ordItem.Attributes = product.AttributeId; _OrderedItemBusiness.Insert(ordItem); _unitOfWork.SaveChanges(); //formatting message totalAmount = totalAmount + (Math.Round((ordItem.Price ?? 0) - (Decimal.Divide(ordItem.DiscountPercent ?? 0, 100) * ordItem.Price ?? 0)) * ordItem.OrderQuantity); itemdetailmessage = itemdetailmessage + @"<tr><td>" + prdt.ProductCode + "</td><td>" + prdt.ProductName + "</td><td>NRs " + (Math.Round((ordItem.Price ?? 0) - (Decimal.Divide(ordItem.DiscountPercent ?? 0, 100) * ordItem.Price ?? 0))) + "</td><td>" + ordItem.OrderQuantity + "</td><td>NRs " + (Math.Round((ordItem.Price ?? 0) - (Decimal.Divide(ordItem.DiscountPercent ?? 0, 100) * ordItem.Price ?? 0)) * ordItem.OrderQuantity) + "</td></tr>"; } } smsmessage = smsmessage + "And total amount is:$ " + totalAmount + Environment.NewLine + Environment.NewLine; smsmessage = smsmessage + "For further information please check your email." + Environment.NewLine + Environment.NewLine + "Ecommerce"; Setting contactUs = db.Settings.AsNoTracking().FirstOrDefault(); CookieStore mycookie = new CookieStore(); var expireCookieTimeHr = Convert.ToInt32(ReadConfigData.GetAppSettingsValue("ExpireCookieTimeHr")); mycookie.SetCookie(Enumerator.CustomerAction.AddToCart.ToString(), "", expireCookieTimeHr); _unitOfWork.Commit(); Session.Remove("CheckOutViewModel"); //sending order mail to customer string messageBody = @"<table style='border-collapse: collapse;' border='0' width='600' cellspacing='0' cellpadding='0' align='center'> <tbody> <tr> <td> </td> </tr> <tr> <td> <table style='border-collapse: collapse;' border='0' width='560' cellspacing='0' cellpadding='0' align='center'> <tbody> <tr> <td style='font-family: Arial, Helvetica, sans-serif; font-size: 16px; line-height: 22px; color: #777777;'>Dear <strong>" + order.FirstName + @"</strong>,</td> </tr> <tr> <td> </td> </tr> <tr> <td style='font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; color: #777777;'>" + mailmessage + @"</td> </tr> <tr> <td> </td> </tr> <tr> <td>Items Ordered</td> </tr> <tr> <td> <table> <thead> <tr> <th>Product Code</th> <th>Product Name</th> <th>Price</th> <th>Quantity</th> <th>Total</th> </tr> </thead> <tbody>" + itemdetailmessage + @"</tbody> <tfoot> <tr> <td colspan='4'>Subtotal</td> <td>$ " + totalAmount + @"</td> </tr> <tr> <td colspan='4'>Grand Total</td> <td>$ " + totalAmount + @"</td> </tr> </tfoot> </table> </td> </tr> <tr> <td> </td> </tr> <tr> <td style='font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; color: #a1004b; font-weight: bold;'>Regards,<br />Call Us On: " + contactUs.Phone + @" </td> </tr> <tr> <td> </td></tr> </tbody> </table> </td> </tr> </tbody> </table>"; string subj = "Order Product"; string tomail = order.Email; //sending order mail to customer service var messageBodycustomerservice = @"<table style='border-collapse: collapse;' border='0' width='600' cellspacing='0' cellpadding='0' align='center'> <tbody> <tr> <td> </td> </tr> <tr> <td> <table style='border-collapse: collapse;' border='0' width='560' cellspacing='0' cellpadding='0' align='center'> <tbody> <tr> <td style='font-family: Arial, Helvetica, sans-serif; font-size: 16px; line-height: 22px; color: #777777;'>Dear <strong>Customer Service</strong>,</td> </tr> <tr> <td> </td> </tr> <tr> <td style='font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; color: #777777;'>" + order.FirstName + " has placed order. His/Her order code is: <strong>" + order.OrderCode + @"</strong></td> </tr> <tr> <td> </td> </tr> <tr> <td>Items Ordered</td> </tr> <tr> <td> <table> <thead> <tr> <th>Product Code</th> <th>Product Name</th> <th>Price</th> <th>Quantity</th> <th>Total</th> </tr> </thead> <tbody>" + itemdetailmessage + @"</tbody> <tfoot> <tr> <td colspan='4'>Subtotal</td> <td>$ " + totalAmount + @"</td> </tr> <tr> <td colspan='4'>Grand Total</td> <td >$ " + totalAmount + @"</td> </tr> </tfoot> </table> </td> </tr> <tr> <td style='font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; color: #a1004b; font-weight: bold;'>With Regards,<br /></td> </tr> <tr> <td> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table>"; var subjcustomerservice = "Order Product"; var tomailcustomerservice = ReadConfigData.GetAppSettingsValue("CustomerServiceEmail"); //sending sms var mobileno = order.Phone; Task SendMailCustomer = Task.Factory.StartNew(() => { //sending mail to customer MailManagement.SendEmail(subj, tomail, messageBody); //sending message to customer service MailManagement.SendEmail(subjcustomerservice, tomailcustomerservice, messageBodycustomerservice); //send sms //SendSMS.Send(mobileno, smsmessage); }); } catch (Exception ex) { _unitOfWork.Rollback(); } clearCart(); return(ordertoken); }