public ActionResult AddOrder()
        {
            OrderModel model      = new OrderModel(_db);
            int        retVal     = -1;
            string     retMessage = "";

            try
            {
                Dictionary <string, object> orderItems = HttpContext.Session.Get <Dictionary <string, object> >(SessionVars.Cart);
                retVal = model.AddOrder(orderItems, HttpContext.Session.GetString(SessionVars.User));
                if (retVal > 0) // order Added
                {
                    retMessage = "Order " + retVal + " Made!";
                }
                else // problem
                {
                    retMessage = "Order not created, try again later";
                }
            }
            catch (Exception ex) // big problem
            {
                retMessage = "Order was not created, try again later! - " + ex.Message;
            }
            HttpContext.Session.Remove(SessionVars.Cart); // clear out current order once persisted
            HttpContext.Session.SetString(SessionVars.Message, retMessage);
            return(Redirect("/Home"));
        }
        public int AddOrder()
        {
            string   CusPhone   = View.CusPhone;
            string   Note       = View.Note;
            string   UserID     = View.UserID;
            float    TotalPrice = View.TotalPrice;
            DateTime OrderDate  = DateTime.Now;
            Order    o          = new Order(1, OrderDate, TotalPrice, Note, UserID, CusPhone, true);

            return(OrderModel.AddOrder(o));
        }
        public ActionResult CheckOut(Bill model)
        {
            //if (!ModelState.IsValid)
            //{
            //    return View("~/Views/ErrorPage/Oops.cshtml");
            //}
            Bill bill = (Bill)Session["FinalBill"];

            model.Rooms = bill.Rooms;
            if (ModelState.IsValid)
            {
                OrderModel om = new OrderModel();
                string     id = "";
                do
                {
                    Random        rand  = new Random();
                    string        input = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                    StringBuilder res   = new StringBuilder();
                    for (int i = 0; i < 10; i++)
                    {
                        res.Append(input[rand.Next(input.Length)]);
                    }
                    id = res.ToString();
                } while (om.CheckOrderID(id));
                bill.OrdedrID         = id;
                bill.Date             = DateTime.Now;
                bill.FullName         = model.FullName;
                bill.Phone            = model.Phone;
                bill.IdentityDocument = model.IdentityDocument;
                int check = 1;
                check = om.AddOrder(bill.OrdedrID, bill.FullName, bill.Date, bill.Phone, bill.IdentityDocument);
                if (check <= 0)
                {
                    return(View("AddError"));
                }
                ViewBag.ID = bill.OrdedrID;
                OrderDetailModel odm = new OrderDetailModel();
                foreach (var item in bill.Rooms)
                {
                    check = odm.AddOrderDetail(bill.OrdedrID, item.RoomID, item.FromDate, item.ToDate);
                    if (check <= 0)
                    {
                        return(View("AddError"));
                    }
                }
                return(View("Success"));
            }
            return(View("Information", model));
        }
Exemple #4
0
 public ActionResult Checkout(OrderModel model)
 {
     if (Session["order"] != null)
     {
         OrderModel.AddOrder(OrderModel.ConvertToOrder(model));
         var order = OrderModel.GetLastOrder();
         foreach (var item in Session["order"] as List <OrderRowModel> )
         {
             item.OrderId = order.Id;
             OrderRowModel.AddOrderRow(OrderRowModel.ConvertToOrderRow(item));
         }
         Session["order"] = null;
         return(RedirectToAction("Receipt"));
     }
     return(RedirectToAction("Index", "Home"));
 }
        // Add the order, pass the session variable info to the db
        public ActionResult AddOrder()
        {
            OrderModel model            = new OrderModel(_db);
            int        retVal           = -1;
            bool       goodsBackOrdered = false;
            KeyValuePair <int, bool> modelReturn;
            string retMessage = "";

            try
            {
                Dictionary <string, object> orderItems = HttpContext.Session.Get <Dictionary <string,
                                                                                              object> >(SessionVariables.Cart);
                modelReturn = model.AddOrder(orderItems,
                                             HttpContext.Session.Get <ApplicationUser>(SessionVariables.User));
                retVal           = modelReturn.Key;
                goodsBackOrdered = modelReturn.Value;

                if (retVal > 0 && !goodsBackOrdered) // Order Added, no goods back ordered
                {
                    retMessage = "Order " + retVal + " Created!";
                }
                else if (retVal > 0 && goodsBackOrdered) //Order Added, goods backordered
                {
                    retMessage = "Order " + retVal + " Created! Some goods were backordered!";
                }
                else // problem
                {
                    retMessage = "Order not added, try again later";
                }
            }
            catch (Exception ex) // big problem
            {
                retMessage = "Order was not created, try again later! - " + ex.Message;
            }
            HttpContext.Session.Remove(SessionVariables.Cart); // clear out current order once persisted
            HttpContext.Session.SetString(SessionVariables.Message, retMessage);
            return(Redirect("/Home"));
        }
 public OrderModel Add(OrderModel model)
 {
     return(_model.AddOrder(model));
 }
 public ActionResult AddOrder(OrderModel orderModel)
 {
     orderModel.AddOrder();
     return(RedirectToAction("Index"));
     //return Content("yes");
 }