Ejemplo n.º 1
0
        public ActionResult Report(SelectDateViewModel model)
        {
            DatabaseControler   dc          = new DatabaseControler();
            SelectDateViewModel selectModel = dc.GetSelectDateModelByCarId(model.CarId);

            selectModel.MonthId = model.MonthId;
            selectModel.YearId  = model.YearId;
            if (!ModelState.IsValid)
            {
                return(View("SelectDate", selectModel));
            }
            PdfController pc = new PdfController();

            return(new FileStreamResult(pc.CreateDistanceReportByCarId(model.CarId, int.Parse(selectModel.Mounth.ToList()[model.MonthId].Value), int.Parse(selectModel.Year.ToList()[model.YearId].Value)), "application/pdf"));
        }
Ejemplo n.º 2
0
        public ActionResult Report(string id)
        {
            DatabaseControler dc = new DatabaseControler();
            var userName         = User.Identity.Name;
            ApplicationUserManager userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var user = userManager.FindByName(userName);
            int Id   = 0;

            if (!int.TryParse(id, out Id))
            {
                return(RedirectToAction("Index", "Home"));
            }
            SelectDateViewModel sdvm = dc.GetSelectDateModelByCarId(Id);

            return(View("SelectDate", sdvm));
        }
Ejemplo n.º 3
0
        public SelectDateViewModel GetSelectDateModelByCarId(int carId)
        {
            List <Travel>        list               = context.Travel.Where(t => t.CarId == carId).ToList();
            List <string>        listYears          = new List <string>();
            List <string>        listMounth         = new List <string>();
            List <DateViewModel> listYearsForModel  = new List <DateViewModel>();
            List <DateViewModel> listMounthForModel = new List <DateViewModel>();
            int           yearId   = 1;
            int           mounthId = 1;
            DateViewModel model    = new DateViewModel();

            model.Id    = 0;
            model.Value = "";
            listMounthForModel.Add(model);
            listYearsForModel.Add(model);
            foreach (Travel t in list)
            {
                if (!listMounth.Contains((t.TravelDate.Month).ToString()))
                {
                    listMounth.Add((t.TravelDate.Month).ToString());
                    DateViewModel dvm = new DateViewModel();
                    dvm.Id    = mounthId;
                    dvm.Value = t.TravelDate.Month.ToString();
                    listMounthForModel.Add(dvm);
                    mounthId++;
                }
                if (!listYears.Contains(t.TravelDate.Year.ToString()))
                {
                    listYears.Add(t.TravelDate.Year.ToString());
                    DateViewModel dvm = new DateViewModel();
                    dvm.Id    = yearId;
                    dvm.Value = t.TravelDate.Year.ToString();
                    listYearsForModel.Add(dvm);
                    yearId++;
                }
            }
            SelectDateViewModel retval = new SelectDateViewModel();

            retval.CarId  = carId;
            retval.Mounth = listMounthForModel;
            retval.Year   = listYearsForModel;
            return(retval);
        }