// GET: checkout public ActionResult Index() { try { if (Session["idUser"] != null) { CheckoutDomain mCheckoutDomain = new CheckoutDomain(); List <CustomerCartDomain> customercartList = new List <CustomerCartDomain>(); var customerCartOrders = CustomerCartCRUD.GetCartByALLCustomerId(Convert.ToInt32(Session["idUser"])); mCheckoutDomain.Id = customerCartOrders[0].Id; mCheckoutDomain.FirstName = customerCartOrders[0].FirstName; mCheckoutDomain.LastName = customerCartOrders[0].LastName; mCheckoutDomain.Email = customerCartOrders[0].Email; mCheckoutDomain.Phone = customerCartOrders[0].Phone; mCheckoutDomain.Country = customerCartOrders[0].Country; mCheckoutDomain.State = customerCartOrders[0].State; mCheckoutDomain.City = customerCartOrders[0].City; mCheckoutDomain.Pincode = customerCartOrders[0].Pincode; mCheckoutDomain.ShippingAddress = customerCartOrders[0].ShippingAddress; mCheckoutDomain.BillingAddress = customerCartOrders[0].BillingAddress; for (int i = 0; i < customerCartOrders.Count(); i++) { CustomerCartDomain mObj = new CustomerCartDomain(); mObj.Amount = customerCartOrders[i].Amount; mObj.Quantity = customerCartOrders[i].Quantity; mObj.ITEM_DESC = customerCartOrders[i].ProductName; mObj.Id = customerCartOrders[i].cartId; mObj.IsPlace = customerCartOrders[i].IsPlaced; customercartList.Add(mObj); } ViewBag.CustomerscartList = customercartList.Where(x => x.IsPlace == false).ToList(); Session["customerCartOrders"] = customercartList; ViewBag.Subtotal = customercartList.Where(x => x.IsPlace == false).Sum(x => x.Amount); return(View(mCheckoutDomain)); } else { return(RedirectToAction("Login", "Customer")); } } catch (Exception ex) { ExceptionLogDomain obj = new ExceptionLogDomain(); obj.MethodName = "Index"; obj.ControllerName = "Checkout"; obj.ErrorText = ex.Message; obj.StackTrace = ex.StackTrace; obj.Datetime = DateTime.Now; ExceptionLogCRUD.AddToExceptionLog(obj); return(RedirectToAction("Index", "Error")); } }
public ActionResult AddToCart(string prodId, string price, string qty) { try { if (Session["idUser"] != null) { Session["QTY"] = qty; CustomerCartDomain mcustomerCart = new CustomerCartDomain(); mcustomerCart.Amount = Convert.ToDecimal(price) * Convert.ToInt32(qty); mcustomerCart.CreatedDatetime = DateTime.Now; mcustomerCart.CustomerId = Session["idUser"].ToString(); mcustomerCart.IsDeleted = "False"; mcustomerCart.Quantity = Convert.ToInt32(qty); mcustomerCart.ProductId = prodId; mcustomerCart.IsPlace = false; CustomerCartCRUD.AddToCart(mcustomerCart); return(Json(true)); } else { return(Json(false)); } } catch (Exception ex) { ExceptionLogDomain obj = new ExceptionLogDomain(); obj.MethodName = "AddToCart"; obj.ControllerName = "Product"; obj.ErrorText = ex.Message; obj.StackTrace = ex.StackTrace; obj.Datetime = DateTime.Now; ExceptionLogCRUD.AddToExceptionLog(obj); return(RedirectToAction("Index", "Error")); } }
public static void AddToCart(CustomerCartDomain mCustomerCart) { string mainconn = ConfigurationManager.ConnectionStrings["conn"].ConnectionString; SqlConnection sqlconn = new SqlConnection(mainconn); SqlCommand cmd = new SqlCommand("sp_cart", sqlconn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@mode", "Insert"); cmd.Parameters.AddWithValue("@CustomerId", mCustomerCart.CustomerId); cmd.Parameters.AddWithValue("@ProductId", mCustomerCart.ProductId); cmd.Parameters.AddWithValue("@CreatedDatetime", mCustomerCart.CreatedDatetime); cmd.Parameters.AddWithValue("@IsDeleted", mCustomerCart.IsDeleted); cmd.Parameters.AddWithValue("@Quantity", mCustomerCart.Quantity); cmd.Parameters.AddWithValue("@Amount", mCustomerCart.Amount); cmd.Parameters.AddWithValue("@IsPlace", mCustomerCart.IsPlace); if (sqlconn.State == ConnectionState.Closed) { sqlconn.Open(); } cmd.ExecuteNonQuery(); sqlconn.Close(); }