예제 #1
0
 // GET: LOAIXEs
 public ActionResult Index()
 {
     return(View(service.GetAll()));
 }
예제 #2
0
        public HttpResponseMessage GetAll(HttpRequestMessage request, int page, int pageSize,
                                          string batDau, string ketThuc, bool vanglai, bool thang, bool sendmail, string trongbai)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpContext.Current.Session[CommonConstants.SessionSumThongKeChiTiet] = new SumThongKeChiTiet();

                HttpContext.Current.Session[CommonConstants.SessionThongKeChiTiet] = new List <ThongKeChiTietViewModel>();

                HttpContext.Current.Session[CommonConstants.SessionListRa] = new List <Ra>();

                try
                {
                    var resultRa = _thongKeNhanhService.GetAll(batDau, ketThuc);

                    if (!resultRa.IsSuccessStatusCode)
                    {
                        return request.CreateErrorResponse(resultRa.StatusCode, resultRa.Content.ReadAsStringAsync().Result);
                    }

                    var resultLoaive = _loaiVeService.GetAll();

                    if (!resultLoaive.IsSuccessStatusCode)
                    {
                        return request.CreateErrorResponse(resultRa.StatusCode, resultRa.Content.ReadAsStringAsync().Result);
                    }

                    var resultNhanVien = _appUser.GetAll();

                    if (!resultNhanVien.IsSuccessStatusCode)
                    {
                        return request.CreateErrorResponse(resultNhanVien.StatusCode, resultNhanVien.Content.ReadAsStringAsync().Result);
                    }

                    var resultLoaXe = _loaiXeService.GetAll();

                    if (!resultLoaXe.IsSuccessStatusCode)
                    {
                        return request.CreateErrorResponse(resultRa.StatusCode, resultRa.Content.ReadAsStringAsync().Result);
                    }

                    var lst_loaixe = resultLoaXe.Content.ReadAsAsync <IEnumerable <LoaiXe> >().Result.ToList();

                    var lst_nhanvien = resultNhanVien.Content.ReadAsAsync <IEnumerable <ApplicationUserViewModel> >().Result.ToList();

                    var lst_loaive = resultLoaive.Content.ReadAsAsync <IEnumerable <LoaiVe> >().Result.ToList();

                    IEnumerable <Ra> lst_ra = resultRa.Content.ReadAsAsync <IEnumerable <Ra> >().Result.ToList();

                    List <ThongKeChiTietViewModel> listData = new List <ThongKeChiTietViewModel>();

                    int soLuotXe, xeVangLai, xeThang;
                    List <ListXe> listXe = new List <ListXe>();

                    if (trongbai != "trongbai")
                    {
                        if (!thang)
                        {
                            lst_ra = lst_ra.Where(_ra => _ra.LoaiVeId > 0).ToList();
                        }
                        if (!vanglai)
                        {
                            lst_ra = lst_ra.Where(_ra => _ra.LoaiVeId < 0).ToList();
                        }
                        int i = 0;
                        long _tongtien = 0;
                        foreach (Ra _ra in lst_ra)
                        {
                            ThongKeChiTietViewModel tkChiTiet = new ThongKeChiTietViewModel();
                            i++;
                            tkChiTiet.STT = i;
                            tkChiTiet.MaThe = _ra.MaThe;
                            tkChiTiet.BienSo = _ra.BienSo;
                            tkChiTiet.GioVao = _ra.GioVao.ToString();
                            tkChiTiet.GioRa = _ra.GioRa.ToString();
                            tkChiTiet.GiaVe = _ra.GiaVe.ToString();
                            _tongtien += _ra.GiaVe.Value;

                            if (_ra.LoaiVeId < 0)
                            {
                                tkChiTiet.LoaiVe = "Vé tháng";
                            }
                            else
                            {
                                LoaiVe loaive = lst_loaive.Where(_lx => _lx.Id == _ra.LoaiVeId).SingleOrDefault();
                                if (loaive != null)
                                {
                                    tkChiTiet.LoaiVe = loaive.Ten;
                                }
                                else
                                {
                                    tkChiTiet.LoaiVe = "Đã xóa";
                                }
                            }

                            if (string.IsNullOrEmpty(_ra.NhanVienId_Vao))
                            {
                                tkChiTiet.NhanVienVao = "Không đăng nhập";
                            }
                            else
                            {
                                if (lst_nhanvien != null)
                                {
                                    ApplicationUserViewModel nv = lst_nhanvien.Where(_mt => _mt.Id == _ra.NhanVienId_Vao).SingleOrDefault();
                                    if (nv != null)
                                    {
                                        tkChiTiet.NhanVienVao = nv.FullName;
                                    }
                                    else
                                    {
                                        tkChiTiet.NhanVienVao = "Đã xóa";
                                    }
                                }
                            }
                            if (string.IsNullOrEmpty(_ra.NhanVienId_Ra))
                            {
                                tkChiTiet.NhanVienRa = "Không đăng nhập";
                            }
                            else
                            {
                                if (lst_nhanvien != null)
                                {
                                    ApplicationUserViewModel nv = lst_nhanvien.Where(_mt => _mt.Id == _ra.NhanVienId_Ra).SingleOrDefault();
                                    if (nv != null)
                                    {
                                        tkChiTiet.NhanVienRa = nv.FullName;
                                    }
                                    else
                                    {
                                        tkChiTiet.NhanVienRa = "Đã xóa";
                                    }
                                }
                            }
                            listData.Add(tkChiTiet);
                        }

                        soLuotXe = i;
                        xeVangLai = lst_ra.Where(_ra => _ra.LoaiVeId > 0).Count();

                        foreach (LoaiXe _loaixe in lst_loaixe)
                        {
                            var list = new ListXe();
                            list.Id = _loaixe.Id;
                            list.Name = _loaixe.Ten;
                            list.Count = lst_ra.Where(_ra => _ra.LoaiVeId == _loaixe.LoaiVeId).Count();
                            listXe.Add(list);
                        }
                        xeThang = lst_ra.Where(_ra => _ra.LoaiVeId < 0).Count();
                    }
                    else
                    {
                        var resultVao = _vaoService.GetVaoTimKiem(null, null, batDau, ketThuc);

                        if (!resultVao.IsSuccessStatusCode)
                        {
                            return request.CreateErrorResponse(resultRa.StatusCode, resultRa.Content.ReadAsStringAsync().Result);
                        }

                        List <Vao> lst_vao = resultVao.Content.ReadAsAsync <IEnumerable <Vao> >().Result.ToList();
                        if (!thang)
                        {
                            lst_vao = lst_vao.Where(_vao => _vao.LoaiVeId > 0).ToList();
                        }
                        if (!vanglai)
                        {
                            lst_vao = lst_vao.Where(_vao => _vao.LoaiVeId < 0).ToList();
                        }

                        int i = 0;
                        foreach (Vao _vao in lst_vao)
                        {
                            ThongKeChiTietViewModel tkChiTiet = new ThongKeChiTietViewModel();
                            i++;
                            tkChiTiet.STT = i;
                            tkChiTiet.MaThe = _vao.MaThe;
                            tkChiTiet.BienSo = _vao.BienSo;
                            tkChiTiet.GioVao = _vao.GioVao.ToString();
                            tkChiTiet.GioRa = "Xe trong bãi";
                            LoaiVe lv = lst_loaive.Where(_lx => _lx.Id == _vao.LoaiVeId).SingleOrDefault();
                            if (lv != null)
                            {
                                LoaiXe lx = lst_loaixe.Where(_lx => _lx.LoaiVeId == _vao.LoaiVeId).SingleOrDefault();
                                if (lx != null)
                                {
                                    if (lx.ThuTienTruoc.Value)
                                    {
                                        // tkChiTiet.GiaVe = lv.tinhveTNXP(_vao.GioVao, _vao.GioVao).ToString("#,##0 VNĐ");
                                        tkChiTiet.GiaVe = "0";
                                    }
                                    else
                                    {
                                        tkChiTiet.GiaVe = "Xe trong bãi";
                                    }
                                }
                            }
                            else
                            {
                                tkChiTiet.GiaVe = "Loại Vé đã xóa";
                            }
                            if (_vao.LoaiVeId < 0)
                            {
                                tkChiTiet.LoaiVe = "Vé tháng";
                            }
                            else
                            {
                                if (lv != null)
                                {
                                    tkChiTiet.LoaiVe = lv.Ten;
                                }
                                else
                                {
                                    tkChiTiet.LoaiVe = "Loại Vé đã xóa";
                                }
                            }
                            if (string.IsNullOrEmpty(_vao.NhanVienId))
                            {
                                tkChiTiet.NhanVienVao = "Không đăng nhập";
                            }
                            else
                            {
                                if (lst_nhanvien != null)
                                {
                                    ApplicationUserViewModel nv = lst_nhanvien.Where(_mt => _mt.Id == _vao.NhanVienId).SingleOrDefault();
                                    if (nv != null)
                                    {
                                        tkChiTiet.NhanVienVao = nv.FullName;
                                    }
                                    else
                                    {
                                        tkChiTiet.NhanVienVao = "Đã xóa nv";
                                    }
                                }
                            }
                            tkChiTiet.NhanVienRa = "Xe trong bãi";
                            listData.Add(tkChiTiet);
                        }

                        soLuotXe = i;
                        xeVangLai = lst_vao.Where(_vao => _vao.LoaiVeId > 0).Count();

                        foreach (LoaiXe _loaixe in lst_loaixe)
                        {
                            var list = new ListXe();
                            list.Id = _loaixe.Id;
                            list.Name = _loaixe.Ten;
                            list.Count = lst_vao.Where(_vao => _vao.LoaiVeId == _loaixe.LoaiVeId).Count();
                            listXe.Add(list);
                        }
                        xeThang = lst_vao.Where(_vao => _vao.LoaiVeId < 0).Count();
                    }
                    int totalRow = listData.Count();

                    var query = listData.OrderBy(x => x.STT).Skip(page * pageSize).Take(pageSize);

                    var sumTk = new SumThongKeChiTiet
                    {
                        SoLuotXe = soLuotXe,
                        XeVangLai = xeVangLai,
                        ListXeVangLai = listXe,
                        XeThang = xeThang
                    };

                    PaginationSet <ThongKeChiTietViewModel> pagedSet = new PaginationSet <ThongKeChiTietViewModel>()
                    {
                        Page = page,
                        TotalCount = totalRow,
                        TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize),
                        Items = query,
                        SumThongKeChiTiet = sumTk
                    };

                    HttpContext.Current.Session[CommonConstants.SessionSumThongKeChiTiet] = sumTk;
                    HttpContext.Current.Session[CommonConstants.SessionThongKeChiTiet] = listData;

                    HttpContext.Current.Session[CommonConstants.SessionListRa] = lst_ra.ToList();

                    var response = request.CreateResponse(HttpStatusCode.OK, pagedSet);

                    return response;
                }
                catch (Exception ex)
                {
                    return null;
                }
            }));
        }