예제 #1
0
        public ActionResult Scan(int?id)
        {
            if (Session["UserID"] != null && Session["UserType"].ToString().ToLower() == "chef")
            {
                if (id == null)
                {
                    return(RedirectToAction("Index"));
                }
                Order ord = oRepo.GetByID((int)id);

                List <DAL.User>         users         = uRepo.GetCurrent();
                List <DAL.Meal>         meals         = mRepo.GetCurrent();
                List <DAL.OrderProduct> orderProducts = opRepo.GetCurrent();
                OrderModel om = new OrderModel();

                if (ord.Date != null)
                {
                    om.Date = (DateTime)ord.Date;
                }
                else
                {
                    om.Date = new DateTime();
                }

                om.EstimatedTime = ord.EstimatedTime;
                om.ID            = ord.ID;
                om.QRCodePath    = ord.QRCodePath;
                om.TotalPrice    = ord.TotalPrice;
                om.Voucher       = null;

                UserModel um = new UserModel();
                if (ord.UserID != null)
                {
                    var usr = uRepo.GetByID((int)ord.UserID);
                    if (usr.DOB != null)
                    {
                        um.DOB = (DateTime)usr.DOB;
                    }
                    else
                    {
                        um.DOB = new DateTime();
                    }

                    um.ID       = usr.ID;
                    um.Mail     = usr.Mail;
                    um.Name     = usr.Name;
                    um.NrOrders = usr.NrOrders;
                    um.Type     = usr.Type;
                }

                om.User = um;

                List <MealModel> mm = new List <MealModel>();
                foreach (DAL.OrderProduct op in orderProducts)
                {
                    if (op.OrderID == ord.ID)
                    {
                        MealModel mealmodel = new MealModel();
                        Meal      meal      = mRepo.GetByID((int)op.MealID);
                        mealmodel.ID   = meal.ID;
                        mealmodel.Name = meal.Name;
                        if (op.Quantity == null)
                        {
                            mealmodel.Quantity = 0;
                        }
                        else
                        {
                            mealmodel.Quantity = (int)op.Quantity;
                        }
                        mm.Add(mealmodel);
                    }
                }
                om.Meals = mm;

                Session["ordID"] = id;
                return(View(om));
            }
            return(RedirectToAction("Login", "Home", new { area = "" }));
        }