示例#1
0
        public ActionResult PlaceOrder(CustomerOrderDomain model)
        {
            try
            {
                var orders = CustomerOrderCRUD.GetCustomerOrderByCustomerId(0);

                int lastOrder = 0;
                if (orders.Count > 1)
                {
                    lastOrder = orders[0].Id;
                }

                model.OrderDate     = DateTime.Now;
                model.PaymentType   = "COD";
                model.TransactionId = "Trans00" + lastOrder + 1;

                CustomerOrderCRUD.AddToCustomerOrder(model);

                List <CustomerCartDomain> sessionCustomerCartOrders = (List <CustomerCartDomain>)Session["customerCartOrders"];
                if (sessionCustomerCartOrders != null)
                {
                    foreach (var item in sessionCustomerCartOrders)
                    {
                        bool res = CustomerCartCRUD.UpdateDetails(item.Id, true);
                    }
                }
                else
                {
                    var customerCartOrders = CustomerCartCRUD.GetCartByALLCustomerId(Convert.ToInt32(Session["idUser"]));
                    foreach (var item in customerCartOrders)
                    {
                        bool res = CustomerCartCRUD.UpdateDetails(item.Id, true);
                    }
                }
                return(Json("True", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ExceptionLogDomain obj = new ExceptionLogDomain();
                obj.MethodName     = "PlaceOrder";
                obj.ControllerName = "Checkout";
                obj.ErrorText      = ex.Message;
                obj.StackTrace     = ex.StackTrace;
                obj.Datetime       = DateTime.Now;
                ExceptionLogCRUD.AddToExceptionLog(obj);

                return(Json("False", JsonRequestBehavior.AllowGet));
            }
        }
        // GET: Order
        public ActionResult Index()
        {
            try
            {
                if (Session["idUser"] != null)
                {
                    int customerID = Convert.ToInt32(Session["idUser"]);
                    var orders     = CustomerOrderCRUD.GetCustomerOrderByCustomerId(customerID);

                    List <Domain.CustomerCartDomain> customercartList = new List <Domain.CustomerCartDomain>();
                    var customerOrders = CustomerCartCRUD.GetCartByALLCustomerId(Convert.ToInt32(Session["idUser"]));
                    for (int i = 0; i < customerOrders.Count(); i++)
                    {
                        Domain.CustomerCartDomain mObj = new Domain.CustomerCartDomain();
                        mObj.Amount    = customerOrders[i].Amount;
                        mObj.Quantity  = customerOrders[i].Quantity;
                        mObj.ITEM_DESC = customerOrders[i].ProductName;
                        mObj.Id        = customerOrders[i].cartId;
                        customercartList.Add(mObj);
                    }
                    ViewBag.CustomerscartList = customercartList;

                    return(View(orders));
                }
                else
                {
                    return(RedirectToAction("Login", "Customer"));
                }
            }
            catch (Exception ex)
            {
                ExceptionLogDomain obj = new ExceptionLogDomain();
                obj.MethodName     = "Index";
                obj.ControllerName = "Order";
                obj.ErrorText      = ex.Message;
                obj.StackTrace     = ex.StackTrace;
                obj.Datetime       = DateTime.Now;

                ExceptionLogCRUD.AddToExceptionLog(obj);
                return(RedirectToAction("Index", "Error"));
            }
        }