예제 #1
0
        public ActionResult History(int PasgoID, int type)
        {
            if (Convert.ToInt32(Session["Level"]) == 1 || Session["Level"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            //Lỗi: Nếu ảnh ko để type=99 -> bị loại -> thiếu lịch sử
            var      x          = Request.Form["from"];
            var      y          = Request.Form["to"];
            DateTime today      = DateTime.Now;
            DateTime defaultmin = DateTime.ParseExact("01-01-2001", "dd-MM-yyyy", CultureInfo.InvariantCulture);
            DateTime from       = defaultmin;
            DateTime to         = DateTime.Now;

            if (x != "" && x != null)
            {
                from = DateTime.ParseExact(x, "yyyy-MM-dd", CultureInfo.InvariantCulture);
            }
            if (y != "" && y != null)
            {
                to = DateTime.ParseExact(y, "yyyy-MM-dd", CultureInfo.InvariantCulture);
            }
            if (to > today)
            {
                to = today;
            }
            if (from > today || from > to)
            {
                TempData["Failed"] = "Nhập thông tin ngày tháng sai";
            }
            System.Diagnostics.Trace.WriteLine("from: " + from + " /to: " + to);
            List <FullInfoHistory_Result> result = db.FullInfoHistory(PasgoID, type, from, to).ToList();

            if (result.Count() == 0)
            {
                TempData["Failed"] = "Lịch sử đặt bàn trống";
                return(View(Tuple.Create(result, PasgoID, type)));
            }
            if (result.Count() > 0 && from > defaultmin)
            {
                TempData["Success"] = "Hiển thị " + result.Count().ToString() + " bản ghi lịch sử đặt chỗ từ " + from.ToString("dd-MMM-yyyy") + " đến " + to.ToString("dd-MMM-yyyy");
                //return View(Tuple.Create(result, PasgoID, type, from, to));
            }
            else
            {
                TempData["Success"] = "Hiển thị " + result.Count().ToString() + " bản ghi lịch sử đặt chỗ từ " + result.ElementAt(result.Count() - 1).CallTime.ToString("dd-MMM-yyyy") + " đến " + result.ElementAt(0).CallTime.ToString("dd-MMM-yyyy");
                //return View(Tuple.Create(result, PasgoID, type, result.ElementAt(result.Count() - 1).CallTime, result.ElementAt(0).CallTime));
            }
            return(View(Tuple.Create(result, PasgoID, type)));
        }