Пример #1
0
        public void UpdateItems(Items item)
        {
            BusinessCartContract.Items businessItem = Mapper.Map <UICartContract.Items, BusinessCartContract.Items>(item);

            cartBL = new CartBL(new Credential {
                UserName = InterplayStorage.SelectedUser.UserName, Password = InterplayStorage.SelectedUser.Password
            });

            BusinessCartContract.Cart cart = null;

            // Open the cart while adding the first item to the cart
            if (CartInstance == null || CartInstance.id == null)
            {
                cart = cartBL.OpenCart();
                // dont use below mapper, its creating new objects, loosing the event handlers, so do it manually
                //_instance = this.ConvertToUICart(cart);
                UpdateUIContract(cart, _instance);
            }

            if (_instance.status == "OPEN" && _instance.type == "Cart")
            {
                cart = cartBL.AddItemsToCart(_instance.id, businessItem);
                // dont use below mapper, its creating new objects, loosing the event handlers, so do it manually
                //_instance = this.ConvertToUICart(cart);
                UpdateUIContract(cart, _instance);

                if (this.cartItemUpdated != null)
                {
                    this.cartItemUpdated.Invoke(_instance);
                }
            }
        }
Пример #2
0
        private void calculateCart()
        {
            double price;
            double discount = (ViewState["discount"] != null) ? double.Parse(ViewState["discount"].ToString()) : 0;
            CartBL cartBL   = new CartBL();

            if (discount > 0)
            {
                foreach (GridViewRow row in dgvCart.Rows)
                {
                    //if (double.Parse(((Label)row.FindControl("lblProductPrice")).Text) == double.Parse(((Label)row.FindControl("lblUserPrice")).Text))
                    //{
                    price = double.Parse(((Label)row.FindControl("lblProductPrice")).Text);
                    double discountPrice = price * (1 - ((double)discount) / 100);
                    double quantity      = double.Parse(((TextBox)row.FindControl("txtQuantity")).Text);
                    int    productID     = int.Parse(((Label)row.FindControl("lblProductID")).Text);
                    ((Label)row.FindControl("lblUserPrice")).Text = string.Format("{0:N2}", discountPrice);
                    ((Label)row.FindControl("lblSum")).Text       = string.Format("{0:N2}", (discountPrice * quantity));
                    cartBL.UpdateCartProduct(Session["cartID"].ToString(), productID, quantity, price, discountPrice, -1);
                    //}
                }
            }

            //calculateTotal();
        }
Пример #3
0
        protected void btnCart_Click(object sender, EventArgs e)
        {
            CartBL cartBL = new CartBL();

            cartBL.AddProductToCart(lblProductID.Value.Contains(',') ? int.Parse(lblProductID.Value.Substring(0, lblProductID.Value.IndexOf(','))) : int.Parse(lblProductID.Value), Session["cartID"].ToString(), 1, double.Parse(lblWebPrice.Text), double.Parse(lblWebPrice.Text));
            //Response.Redirect("/korpa");
        }
        public ActionResult DeleteCart(Guid cartId)
        {
            var      objResponse = new ResponseObject();
            CartList cartList    = new CartList();

            string SessionID = string.Empty;

            if (Session["sessionid"] == null)
            {
                SessionID = Convert.ToString(Session["sessionid"]);
            }
            string userName = string.IsNullOrEmpty(Convert.ToString(User.Identity.Name)) ? string.Empty : User.Identity.Name;
            var    user     = UserManager.Users.Where(u => u.Email == userName).FirstOrDefault();
            CartBL obj      = new CartBL();
            int    value    = obj.DeleteCart(cartId, SessionID, user);

            obj = null;
            if (value > 0)
            {
                objResponse.IsSuccess      = "true";
                objResponse.StrResponse    = CommonFunction.SuccessMessage("Cart.", "Product deleted successfully.");
                cartList.CartViewModelList = this.RefreshList();
            }
            else
            {
                objResponse.IsSuccess   = "false";
                objResponse.StrResponse = CommonFunction.ErrorMessage("Cart.", "Something went wrong!");
            }
            return(Json(new
            {
                html = this.RenderRazorViewToString("_getCartList", cartList),
                objResponse
            }, JsonRequestBehavior.AllowGet));
        }
Пример #5
0
        private Order createOrder(int userID)
        {
            Order order = new Order();

            order.Date      = DateTime.Now.ToUniversalTime();
            order.Firstname = txtFirstname.Text;
            order.Lastname  = txtLastname.Text;
            order.Address   = txtAddress.Text;
            order.City      = txtCity.Text;
            order.Phone     = txtPhone.Text;
            order.Email     = txtEmail.Text;
            order.Items     = getItems();
            order.User      = new User(userID, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, null, string.Empty, string.Empty, DateTime.Now, string.Empty, 0, 1);
            order.Name      = (rdbUserType.SelectedValue == "2") ? txtCompanyName.Text : string.Empty;
            order.Pib       = (rdbUserType.SelectedValue == "2") ? txtPib.Text : string.Empty;
            //order.Payment = (order.Name != string.Empty) ? new Payment(int.Parse(rdbPaymentCompany.SelectedValue), rdbPaymentCompany.SelectedItem.Text) : new Payment(int.Parse(rdbPayment.SelectedValue.ToString()), rdbPayment.SelectedItem.Text);
            order.Payment  = new Payment(int.Parse(rdbPayment.SelectedValue), rdbPayment.SelectedItem.Text);
            order.Delivery = new Delivery(int.Parse(rdbDelivery.SelectedValue.ToString()), rdbDelivery.SelectedItem.Text);
            CartBL cartBL = new CartBL();

            order.Coupon      = new Coupon(cartBL.GetCartCoupon(Session["cartID"].ToString()), string.Empty, 0, string.Empty, DateTime.Now, DateTime.Now, null, null);
            order.OrderStatus = new OrderStatus(1, string.Empty);
            order.Zip         = txtZip.Text;
            order.Comment     = txtRemark.Text;
            order.CartID      = Session["cartID"].ToString();


            OrderBL orderBL = new OrderBL();

            orderBL.SaveOrder(order);
            return(order);
        }
Пример #6
0
 protected void dgvCart_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     switch (e.CommandName)
     {
     case "UpdateQuantity":
     {
         GridViewRow row          = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
         int         productID    = int.Parse(((Label)row.Cells[0].FindControl("lblProductID")).Text);
         double      productPrice = double.Parse(((Label)row.Cells[0].FindControl("lblProductPrice")).Text);
         double      userPrice    = double.Parse(((Label)row.Cells[0].FindControl("lblUserPrice")).Text);
         int         quantity;
         if (!int.TryParse(((TextBox)row.Cells[0].FindControl("txtQuantity")).Text, out quantity))
         {
             Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('wrong')</SCRIPT>");
             break;
         }
         else
         {
             CartBL cartBL = new CartBL();
             cartBL.UpdateCartProduct(Session["cartID"].ToString(), productID, quantity, productPrice, userPrice, -1);
             calculateItem(row.RowIndex, userPrice * quantity);
             calculateTotal();
         }
         break;
     }
     }
 }
Пример #7
0
        public static string AddToCart(int productID, double webPrice)
        {
            CartBL cartBL = new CartBL();

            cartBL.AddProductToCart(productID, System.Web.HttpContext.Current.Session["cartID"].ToString(), 1, webPrice, webPrice);
            return(JsonConvert.SerializeObject((cartBL.GetProductsCount(System.Web.HttpContext.Current.Session["cartID"].ToString()).ToString() + "|" + string.Format("{0:N2}", cartBL.GetTotal(System.Web.HttpContext.Current.Session["cartID"].ToString()))).Split('|')));
        }
Пример #8
0
 public ShoppingCartModel(IProductData productData, CartBL cartBL, UserManager <ApplicationUser> userManager, IMembershipData membershipData)
 {
     this.productData    = productData;
     this.cartBL         = cartBL;
     this.userManager    = userManager;
     this.membershipData = membershipData;
     CartItems           = new List <ShoppingCart>();
 }
Пример #9
0
        public void LoadCart()
        {
            DataTable cart = new CartBL().GetProducts(Session["cartID"].ToString());

            double cartTotal = 0;
            double taxBase   = 0;
            double tax       = 0;
            double discount  = 0;
            double delivery  = 0;
            double total     = 0;
            double saving    = 0;
            int    couponID  = 1;

            for (int i = 0; i < cart.Rows.Count; i++)
            {
                cartTotal += double.Parse(cart.Rows[i]["productPrice"].ToString()) * double.Parse(cart.Rows[i]["quantity"].ToString());
                discount  += double.Parse(cart.Rows[i]["userPrice"].ToString()) * double.Parse(cart.Rows[i]["quantity"].ToString());
                if (int.Parse(cart.Rows[i]["couponID"].ToString()) > 1)
                {
                    couponID = int.Parse(cart.Rows[i]["couponID"].ToString());
                }
            }

            if (couponID > 1)
            {
                lblRemoveCoupon.Visible = true;
            }
            else
            {
                lblRemoveCoupon.Visible = false;
            }

            lblProductCount.Text = cart.Rows.Count.ToString();
            taxBase = discount / 1.2;
            tax     = discount - taxBase;

            delivery = rdbDelivery.SelectedValue != "2" ? ((cartTotal > double.Parse(ConfigurationManager.AppSettings["freeDeliveryTotalValue"])) ? 0 : double.Parse(ConfigurationManager.AppSettings["deliveryCost"])) : 0;

            total  = discount + delivery;
            saving = cartTotal - discount;

            Coupon coupon = new CouponBL().GetCoupon(couponID);

            if (coupon != null)
            {
                lblCoupon.Text = coupon.Code;
            }
            else
            {
                lblCoupon.Text = string.Empty;
            }

            lblCartValue.Text     = string.Format("{0:N2}", cartTotal);
            lblDeliveryPrice.Text = string.Format("{0:N2}", delivery);
            lblTotal.Text         = string.Format("{0:N2}", total);
            lblDiscount.Text      = string.Format("{0:N2}", saving);
        }
Пример #10
0
 public CheckoutModel(IOrderData orderData, UserManager <ApplicationUser> userManager, IProductData productData, IMembershipData membershipData, CartBL cartBL)
 {
     this.orderData      = orderData;
     this.userManager    = userManager;
     this.productData    = productData;
     this.membershipData = membershipData;
     this.cartBL         = cartBL;
     OrderDetails        = new List <OrderDetail>();
 }
Пример #11
0
        protected void btnDeleteCoupon_Click(object sender, EventArgs e)
        {
            ViewState["discount"] = 0;
            calculateCart();
            CartBL cartBL = new CartBL();

            cartBL.SaveCartCoupon(Session["cartID"].ToString(), -1);
            //btnDeleteCoupon.Visible = false;
        }
Пример #12
0
        protected override void Render(HtmlTextWriter writer)
        {
            CartBL cartBL = new CartBL();

            lblProductCount.Text = cartBL.GetProductsCount(Session["cartID"].ToString()).ToString();
            lblCartPrice.Text    = string.Format("{0:N2}", cartBL.GetTotal(Session["cartID"].ToString()));

            //lblWishListCount.Text = (Page.User.Identity.IsAuthenticated) ? new WishListBL().GetWishListProducts(int.Parse(Membership.GetUser().ProviderUserKey.ToString())).Count().ToString() : "0";
            base.Render(writer);
        }
Пример #13
0
        public static string GetCart()
        {
            DataTable cartProducts = new CartBL().GetProducts(HttpContext.Current.Session["cartID"].ToString());

            for (int i = 0; i < cartProducts.Rows.Count; i++)
            {
                string path = new ProductBL().CreateImageDirectory(int.Parse(cartProducts.Rows[i]["imageUrl"].ToString().Substring(0, cartProducts.Rows[i]["imageUrl"].ToString().LastIndexOf('.')))) + cartProducts.Rows[i]["imageUrl"].ToString().Substring(0, cartProducts.Rows[i]["imageUrl"].ToString().LastIndexOf('.')) + "-" + ConfigurationManager.AppSettings["thumbName"] + cartProducts.Rows[i]["imageUrl"].ToString().Substring(cartProducts.Rows[i]["imageUrl"].ToString().LastIndexOf('.'));
                cartProducts.Rows[i]["imageUrl"] = File.Exists(HttpContext.Current.Server.MapPath(path)) ? path : "/images/no-image.jpg";
            }
            return(JsonConvert.SerializeObject(cartProducts));
        }
Пример #14
0
 protected void dgvCart_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     if (dgvCart.Rows.Count > 0)
     {
         CartBL cartBL = new CartBL();
         int    status = cartBL.DeleteProductFromCart(int.Parse(dgvCart.DataKeys[e.RowIndex].Values[0].ToString()), Session["cartID"].ToString());
         //setValues();
         //Response.Redirect("/cart.aspx");
         loadCart();
         //((CartFirstPage)Page.Master.FindControl("CartFirstPage1")).ProductsCount = dgvCart.Rows.Count;
     }
 }
Пример #15
0
        private List <OrderItem> getItems()
        {
            CartBL    cartBL    = new CartBL();
            DataTable cartItems = cartBL.GetProducts(Session["cartID"].ToString());

            List <OrderItem> items = new List <OrderItem>();

            for (int i = 0; i < cartItems.Rows.Count; i++)
            {
                items.Add(new OrderItem(-1, -1, new ProductBL().GetProduct(int.Parse(cartItems.Rows[i]["productID"].ToString()), string.Empty, false, string.Empty), double.Parse(cartItems.Rows[i]["productPrice"].ToString()), double.Parse(cartItems.Rows[i]["userPrice"].ToString()), double.Parse(cartItems.Rows[i]["quantity"].ToString())));
            }
            return(items);
        }
Пример #16
0
        public void LoadCart()
        {
            CartBL cartBL = new CartBL();

            dgvCart.DataSource = cartBL.GetProducts(Session["cartID"].ToString());
            dgvCart.DataBind();
            ViewState.Add("discount", cartBL.GetCartDiscount(Session["cartID"].ToString()));
            calculateCart();
            if (dgvCart.Rows.Count == 0)
            {
                lblStatus.Text    = "Nemate proizvoda u korpi";
                lblStatus.Visible = true;
            }
        }
Пример #17
0
        public void SuspendCart()
        {
            cartBL = new CartBL(
                new Credential {
                UserName = InterplayStorage.SelectedUser.UserName, Password = InterplayStorage.SelectedUser.Password
            });

            cartBL.AbandonCart(_instance.id);
            this.ClearCartData();

            if (this.cartSuspended != null)
            {
                _instance.cartSuspended.Invoke();
            }
        }
Пример #18
0
        private void CreateActiveCartsbuttons()
        {
            CartBL cartBL = new CartBL(new Credential {
                UserName = InterplayStorage.SelectedUser.UserName, Password = InterplayStorage.SelectedUser.Password
            });
            List <Cart> carts = cartBL.GetActiveCartsByUser();

            foreach (Cart cart in carts)
            {
                InterPlayPOSCartButton button = new InterPlayPOSCartButton();
                button.Cart   = cart;
                button.Text   = cart.cartId;
                button.Click += Cart_Button_Click;
                this.flowLayoutPanelCarts.Controls.Add(button);
            }
        }
Пример #19
0
        public List <CartViewModel> RefreshList()
        {
            string SessionID = string.Empty;

            if (Session["sessionid"] != null)
            {
                SessionID = Convert.ToString(Session["sessionid"]);
            }
            string userName     = string.IsNullOrEmpty(Convert.ToString(User.Identity.Name)) ? string.Empty : User.Identity.Name;
            var    user         = UserManager.Users.Where(u => u.Email == userName).FirstOrDefault();
            CartBL obj          = new CartBL();
            var    cartModelLst = obj.GetCartlist(SessionID, user);

            obj = null;
            return(cartModelLst);
        }
Пример #20
0
        public void CheckOutCart()
        {
            cartBL = new CartBL(new Credential {
                UserName = InterplayStorage.SelectedUser.UserName, Password = InterplayStorage.SelectedUser.Password
            });

            cartBL.CheckOutCart(_instance.id);
            this.ClearCartData();

            if (_instance != null)
            {
                if (_instance.newCartCreated != null)
                {
                    _instance.newCartCreated.Invoke();
                }
            }
        }
Пример #21
0
        private Order createOrder(User user)
        {
            Order order = new Order();

            order.Date      = DateTime.Now.ToUniversalTime();
            order.Firstname = txtFirstname.Text;
            order.Lastname  = txtLastname.Text;
            order.Address   = txtAddress.Text;
            order.City      = txtCity.Text;
            order.Phone     = txtPhone.Text;
            order.Email     = txtEmail.Text;
            order.Items     = getItems();
            //order.User = new User(userID, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, null, string.Empty, string.Empty, DateTime.Now, string.Empty, 0, 1);
            order.User     = user;
            order.Name     = (rdbUserType.SelectedValue == "2") ? txtCompanyName.Text : string.Empty;
            order.Pib      = (rdbUserType.SelectedValue == "2") ? txtPib.Text : string.Empty;
            order.Payment  = (order.Name != string.Empty) ? new Payment(int.Parse(rdbPaymentCompany.SelectedValue), rdbPaymentCompany.SelectedItem.Text) : new Payment(int.Parse(rdbPayment.SelectedValue.ToString()), rdbPayment.SelectedItem.Text);
            order.Delivery = new Delivery(int.Parse(rdbDelivery.SelectedValue.ToString()), rdbDelivery.SelectedItem.Text);
            CartBL cartBL = new CartBL();

            order.Coupon      = new Coupon(cartBL.GetCartCoupon(Session["cartID"].ToString()), string.Empty, 0, string.Empty, DateTime.Now, DateTime.Now, new CouponType(-1, string.Empty), null);
            order.OrderStatus = new OrderStatus(1, string.Empty);
            order.Zip         = txtZip.Text;
            order.Comment     = txtRemark.Text;
            order.CartID      = Session["cartID"].ToString();

            double total = 0;

            foreach (OrderItem item in order.Items)
            {
                if (!bool.Parse(ConfigurationManager.AppSettings["userDiscountOnlyOnProductNotOnPromotion"]) || item.ProductPrice == item.UserPrice)
                {
                    total += item.UserPrice * item.Quantity;
                }
            }

            order.UserDiscountValue = user.DiscountTypeID == 1 ? total * user.Discount / 100 : user.Discount;



            OrderBL orderBL = new OrderBL();

            orderBL.SaveOrder(order);
            return(order);
        }
Пример #22
0
        public ActionResult CheckOutOnePage(CheckOutViewModel model)
        {
            var    objResponse = new ResponseObject();
            string msg         = string.Empty;

            if (model != null && ModelState.IsValid)
            {
                string userName = string.IsNullOrEmpty(Convert.ToString(User.Identity.Name)) ? string.Empty : User.Identity.Name;

                if (string.IsNullOrEmpty(userName))
                {
                    ViewBag.msg = "Please login for your order confirmation";
                    return(View("Index"));
                }
                else
                {
                    Session["invoiceno"] = Guid.NewGuid();
                    string SessionID = string.Empty;
                    if (Session["sessionid"] != null)
                    {
                        SessionID = Convert.ToString(Session["sessionid"]);
                    }

                    CartBL objcart = new CartBL();
                    Int64  value   = objcart.UpdateCartWithUserId(SessionID, userName);
                    objcart = null;
                    Session["checkoutmodel"] = model;
                    //UserRepo objuser = new UserRepo();
                    //int value1 = objuser.UpdateUserInfo(model.BillingModel);
                    //objuser = null;
                    return(RedirectToAction("PayNowCart", model));
                }
            }
            else
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage));
                objResponse.IsSuccess   = "false";
                objResponse.StrResponse = CommonFunction.ErrorMessage(CommonMessagetype.TechnicalError.ToString(), CommonMessage.ErrorMessage);
            }
            return(View("Index"));
        }
Пример #23
0
 private void loadCheckout()
 {
     CartBL cartBL = new CartBL();
     //checkoutInfo1.CartItems = cartBL.GetProducts(Session["cartID"].ToString());
 }
Пример #24
0
        public ActionResult PayNowCart(CheckOutViewModel checkoutViewModel)
        {
            if (checkoutViewModel != null && ModelState.IsValid)
            {
                string SessionID = string.Empty;
                if (Session["sessionid"] != null)
                {
                    SessionID = Convert.ToString(Session["sessionid"]);
                }
                string userName = string.IsNullOrEmpty(Convert.ToString(User.Identity.Name)) ? string.Empty : User.Identity.Name;
                if (string.IsNullOrEmpty(userName))
                {
                    ViewBag.msg = "Please login for your order confirmation";
                    return(View("Index"));
                }
                else
                {
                    Session["invoiceno"]     = Guid.NewGuid();
                    Session["checkoutmodel"] = checkoutViewModel;
                    CartBL objcart = new CartBL();
                    Int64  value   = objcart.UpdateCartWithUserId(SessionID, userName);
                    objcart = null;

                    //UserRepo objuser = new UserRepo();
                    //int value1 = objuser.UpdateUserInfo(model.BillingModel);
                    //objuser = null;
                    // return RedirectToAction("PayNowCart", model);
                }
                UserRepo objuser = new UserRepo();
                var      user    = objuser.GetUserInfo(userName);
                //var user = UserManager.Users.Where(u => u.Email == userName).FirstOrDefault();

                CartBL obj          = new CartBL();
                var    cartModelLst = obj.GetCartlist(SessionID, user);
                obj = null;

                string             Email          = user.Email;
                UserOrderViewModel orderViewModel = new UserOrderViewModel();
                orderViewModel.Address    = checkoutViewModel.BillingModel.AddressBlock;
                orderViewModel.City       = checkoutViewModel.BillingModel.City;
                orderViewModel.Country    = checkoutViewModel.BillingModel.Country;
                orderViewModel.FirstName  = checkoutViewModel.BillingModel.FirstName;
                orderViewModel.LastName   = checkoutViewModel.BillingModel.LastName;
                orderViewModel.PostalCode = checkoutViewModel.BillingModel.ZipCode;
                orderViewModel.State      = checkoutViewModel.BillingModel.State;
                orderViewModel.Mobile     = checkoutViewModel.BillingModel.Mobile;

                orderViewModel.AddressShipping    = checkoutViewModel.ShippingModel.AddressBlock;
                orderViewModel.CityShipping       = checkoutViewModel.ShippingModel.City;
                orderViewModel.CountryShipping    = checkoutViewModel.ShippingModel.Country;
                orderViewModel.FirstNameShipping  = checkoutViewModel.ShippingModel.FirstName;
                orderViewModel.LastNameShipping   = checkoutViewModel.ShippingModel.LastName;
                orderViewModel.PostalCodeShipping = checkoutViewModel.ShippingModel.ZipCode;
                orderViewModel.StateShipping      = checkoutViewModel.ShippingModel.State;
                orderViewModel.MobileShipping     = checkoutViewModel.ShippingModel.Mobile;

                orderViewModel.OrderDate = DateTime.Now;
                orderViewModel.InvoiceNo = Convert.ToString(Session["invoiceno"]);
                orderViewModel.Email     = Email;
                orderViewModel.IpAddress = Request.ServerVariables["REMOTE_ADDR"];
                orderViewModel.UserId    = user.Id;

                List <OrderDetailViewModel> orderDetailViewModelList = new List <OrderDetailViewModel>();
                string detl = "<table border='1'>";
                detl += "<thead>";
                detl += "<tr>";
                detl += "<th>Srno</th>";
                detl += "<th>Product</th>";
                detl += "<th>Qty</th>";
                detl += "<th>Price</th>";
                detl += "<th>Amount</th>";
                detl += "</tr>";
                detl += "</thead>";
                detl += "<tbody>";
                int     srno        = 1;
                decimal totalAmount = 0;
                foreach (var cart in cartModelLst)
                {
                    OrderDetailViewModel od = new OrderDetailViewModel();
                    od.ProductId = cart.ProductId;
                    od.Quantity  = cart.Qty;
                    od.UnitPrice = cart.SalePrice;
                    od.Discount  = 0;
                    orderDetailViewModelList.Add(od);
                    detl        += "<tr>";
                    detl        += "<td>" + srno++ + "</td>";
                    detl        += "<td>" + cart.ProductName + "</td>";
                    detl        += "<td>" + cart.Qty + "</td>";
                    detl        += "<td> Rs." + String.Format("{0:0.00}", cart.SalePrice) + "</td>";
                    detl        += "<td> Rs." + String.Format("{0:0.00}", cart.Qty * cart.SalePrice) + "</td>";
                    detl        += "</tr>";
                    totalAmount += (cart.Qty * cart.SalePrice);
                }
                detl += "<tr>";
                detl += "<td colspan='4' align='right'>Sub Total</td>";
                detl += "<td>" + String.Format("{0:0.00}", totalAmount) + "</td>";
                detl += "</tr>";
                detl += "</tbody>";
                detl += "</table>";
                orderViewModel.OrderDetailViewModelList = orderDetailViewModelList;
                orderViewModel.Total = Convert.ToDecimal(totalAmount);

                // remove detail from cart
                OrderBL objOrder = new OrderBL();
                Int64   OrderId  = objOrder.AddToOrder(orderViewModel);
                objOrder = null;
                //CartRepoModel objCart = new CartRepoModel();
                //int value = objCart.RemoveFromCart(UserId);
                //objCart = null;


                // mail to admin
                #region "Send mail by admin"
                string htmlString = CommonFunction.ReadHtmlTemplate("order");

                htmlString = htmlString.Replace("@@sitename@@", CommonFunction.SiteName)
                             .Replace("@@emailid@@", Email).Replace("@@orderdate@@", orderViewModel.OrderDate.ToString("dd-MM-yyyy"))
                             .Replace("@@invoiceno@@", orderViewModel.InvoiceNo)
                             .Replace("@@username@@", orderViewModel.FirstName + " " + orderViewModel.LastName)
                             .Replace("@@detail@@", detl);
                // var flag = CF.SendMail(CommonFunction.AdminEmail, CommonFunction.AdminEmail, "Order place", htmlString);
                // CommonFunction.SendEmail(Email, "Confirm your account",htmlString);
                CommonFunction.SendByAdminGmail(Email, "Order place", htmlString);

                #endregion

                // redirect to payment gateway

                return(RedirectToAction("Index", "Thanks"));
            }
            else
            {
            }
            return(View());
        }
 public CartController(DbXCART db)
 {
     bl = new CartBL(db);
 }
        public async Task <ActionResult> AddToCart(int?color, Guid?productId, int qty)
        {
            var      objResponse = new ResponseObject();
            CartList cartList    = new CartList();

            if (productId != null)
            {
                ProductsBL objProduct = new ProductsBL();
                var        Product    = objProduct.GetProductDetail(productId);
                objProduct = null;

                if (Product != null)
                {
                    CartViewModel model = new CartViewModel();
                    model.ProductId = Product.Id;
                    model.SalePrice = Product.SalePrice;
                    string UserId = string.IsNullOrEmpty(Convert.ToString(User.Identity.Name)) ? string.Empty : User.Identity.Name;
                    var    user   = await UserManager.FindByNameAsync(UserId);

                    model.UserId = user.Id;
                    if (Session["sessionid"] == null)
                    {
                        Session["sessionid"] = Session.SessionID;
                    }
                    model.SessionId = Convert.ToString(Session["sessionid"]);
                    model.Qty       = qty;
                    CartBL obj = new CartBL();
                    Guid   Id  = obj.AddCart(model);
                    obj = null;

                    if (Id != null)
                    {
                        objResponse.IsSuccess   = "true";
                        objResponse.StrResponse = CommonFunction.SuccessMessage("Cart.", " Product added successfully.");
                        var list = this.RefreshList();
                        cartList.CartViewModelList = list;
                        cartList.Counter           = list.Count();
                    }

                    else
                    {
                        objResponse.IsSuccess   = "false";
                        objResponse.StrResponse = CommonFunction.ErrorMessage("Cart.", "Oops something went wrong.");
                    }
                }
                else
                {
                    objResponse.IsSuccess   = "false";
                    objResponse.StrResponse = CommonFunction.ErrorMessage("Cart.", "Product not found");
                }
            }
            else
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage));
                objResponse.IsSuccess   = "false";
                objResponse.StrResponse = CommonFunction.ErrorMessage(CommonMessagetype.TechnicalError.ToString(), CommonMessage.ErrorMessage);
            }
            return(Json(new
            {
                objResponse,
                html = this.RenderRazorViewToString("_miniCart", cartList),
            }, JsonRequestBehavior.AllowGet));
        }