Beispiel #1
0
        public ActionResult ClientInspections(int carId, string sortOrder, string searchString)
        {
            var futureNotifications   = _inspectionService.GetFutureInspectionsForCar(carId);
            var notificationViewModel = new List <NotificationViewModel>();

            foreach (var notification in futureNotifications)
            {
                var model = new NotificationViewModel()
                {
                    CarId              = notification.CarId,
                    InspectionId       = notification.Id,
                    InspectionDate     = notification.InspectionDate.AddYears(notification.NextInspectionYears),
                    Make               = notification.Car.Make,
                    Model              = notification.Car.Model,
                    Customer           = notification.Car.User.LastName + " " + notification.Car.User.FirstName,
                    ContactDetails     = "P1: " + notification.Car.User.Phone1 + ",P2: " + notification.Car.User.Phone2 + ",E: " + notification.Car.User.Email,
                    Comment            = notification.Comments,
                    RegistrationNumber = notification.Car.RegistrationNumber
                };
                notificationViewModel.Add(model);
            }

            ViewBag.SortOrder = sortOrder;
            ViewBag.InspectionDateSortParm     = String.IsNullOrEmpty(sortOrder) ? "InspectionDate_desc" : "";
            ViewBag.MakeSortParm               = sortOrder == "Make" ? "Make_desc" : "Make";
            ViewBag.ModelSortParm              = sortOrder == "Model" ? "Model_desc" : "Model";
            ViewBag.CustomerSortParm           = sortOrder == "Customer" ? "Customer_desc" : "Customer";
            ViewBag.ContactDetailsSortParm     = sortOrder == "ContactDetails" ? "ContactDetails_desc" : "ContactDetails";
            ViewBag.CommentSortParm            = sortOrder == "Comment" ? "Comment_desc" : "Comment";
            ViewBag.RegistrationNumberSortParm = sortOrder == "RegistrationNumber" ? "RegistrationNumber_desc" : "RegistrationNumber";

            var inspections = from inspection in notificationViewModel
                              select inspection;

            if (!String.IsNullOrEmpty(searchString))
            {
                inspections = inspections.Where(inspection => (inspection.InspectionDate != null && inspection.InspectionDate.ToString().Contains(searchString)) ||
                                                inspection.Make.Contains(searchString) ||
                                                inspection.Model.Contains(searchString) ||
                                                inspection.Customer.Contains(searchString) ||
                                                inspection.ContactDetails.Contains(searchString) ||
                                                (inspection.Comment != null && inspection.Comment.Contains(searchString)) ||
                                                inspection.RegistrationNumber.Contains(searchString));
            }
            switch (sortOrder)
            {
            case "InspectionDate_desc":
                inspections = inspections.OrderByDescending(inspection => inspection.InspectionDate);
                break;

            case "Make":
                inspections = inspections.OrderBy(inspection => inspection.Make);
                break;

            case "Make_desc":
                inspections = inspections.OrderByDescending(inspection => inspection.Make);
                break;

            case "Model":
                inspections = inspections.OrderBy(inspection => inspection.Model);
                break;

            case "Model_desc":
                inspections = inspections.OrderByDescending(inspection => inspection.Model);
                break;

            case "Customer":
                inspections = inspections.OrderBy(inspection => inspection.Customer);
                break;

            case "Customer_desc":
                inspections = inspections.OrderByDescending(inspection => inspection.Customer);
                break;

            case "ContactDetails":
                inspections = inspections.OrderBy(inspection => inspection.ContactDetails);
                break;

            case "ContactDetails_desc":
                inspections = inspections.OrderByDescending(inspection => inspection.ContactDetails);
                break;

            case "Comment":
                inspections = inspections.OrderBy(inspection => inspection.Comment);
                break;

            case "Comment_desc":
                inspections = inspections.OrderByDescending(inspection => inspection.Comment);
                break;

            case "RegistrationNumber":
                inspections = inspections.OrderBy(inspection => inspection.RegistrationNumber);
                break;

            case "RegistrationNumber_desc":
                inspections = inspections.OrderByDescending(inspection => inspection.RegistrationNumber);
                break;

            default:
                inspections = inspections.OrderBy(inspection => inspection.InspectionDate);
                break;
            }

            return(View(inspections.ToList()));
        }