示例#1
0
        public ActionResult GetSquawksForAircraft(int id)
        {
            Aircraft aircraft = _dataService.GetAircraftById(id);

            if (aircraft == null)
            {
                throw new HttpException(404, "Aircraft Not Found");
            }

            List <Squawk> squawks = _dataService.GetSquawksByAircraftId(id);

            ProfileCommon profile = HttpContext.Profile as ProfileCommon;

            if (profile == null)
            {
                RedirectToAction("LogOn", "Account");
            }


            SquawksForAircraftViewModel viewModel = new SquawksForAircraftViewModel()
            {
                AircraftId         = id,
                RegistrationNumber = aircraft.RegistrationNumber,
                Name    = aircraft.Name,
                Squawks = squawks.ConvertToSquawkItemViewModel(),
            };

            bool isOwner = _dataService.IsAircraftOwner(profile.MemberId, id);

            if (isOwner || User.IsInRole(UserRoles.Admin.ToString()) || User.IsInRole(UserRoles.AircraftMaintenance.ToString()))
            {
                viewModel.CanResolveSquawks = true;
            }
            else
            {
                viewModel.CanResolveSquawks = false;
            }

            return(View(ViewNames.SquawksForAircraft, viewModel));
        }
示例#2
0
        private bool ValidateReservation(ReservationViewModel model)
        {
            if (!_dataService.IsValidReservationDateRange(model.Id, model.AircraftId,
                                                          model.StartDate.Date.Add(TimeSpan.Parse(model.StartTime)),
                                                          model.EndDate.Date.Add(TimeSpan.Parse(model.EndTime))))
            {
                ModelState.AddModelError(string.Empty, "A reservation already exists for this time period.");
            }

            // require provide instructor for non-checked out aircraft
            if ((model.InstructorId == null || model.InstructorId == 0))
            {
                // exclude instructors and this aircraft owners
                if (!(User.IsInRole(UserRoles.Instructor.ToString()) | _dataService.IsAircraftOwner(model.MemberId, model.AircraftId)))
                {
                    Member member = _dataService.GetMemberWithPilotData(model.MemberId);
                    if (member.Checkouts.FirstOrDefault(c => c.AircraftId == model.AircraftId) == null)
                    {
                        ModelState.AddModelError(String.Empty, "Records indicate you are not checked out in this airplane.\nPlease add club instructor to your reservation or use different airplane.");
                    }
                }
            }

            List <Reservation> existingReservations = _dataService.GetReservationListByMember(model.MemberId);
            DateTime           today = DateTime.Now;

            // do not allow more than one reservation more than 10 days ahead
            if (model.StartDate >= today.AddDays(10))
            {
                // find all other with start date more than 10 days
                Reservation advanceReservation = existingReservations.FirstOrDefault(r => (r.StartDate >= today.AddDays(10)) && r.Id != model.Id);
                if (advanceReservation != null)
                {
                    ModelState.AddModelError(string.Empty,
                                             String.Format("One reservation already exists for time period 10 or more days ahead (start date {0}).\nYou are only allowed to have one reservation more than 10 days in advance",
                                                           advanceReservation.StartDate.ToString("yyyy-MM-dd hh:mm")));
                }
            }

            // check if there are any other aircraft reservations for the same period (excluding current one if updating)
            DateTime    newReservationStart = model.StartDate.Add(TimeSpan.Parse(model.StartTime));
            DateTime    newReservationEnd   = model.EndDate.Add(TimeSpan.Parse(model.EndTime));
            Reservation overlapReservation  = existingReservations.FirstOrDefault(r => r.Id != model.Id &&
                                                                                  (
                                                                                      (r.StartDate <= newReservationStart && r.EndDate > newReservationStart) ||
                                                                                      (r.StartDate < newReservationEnd && r.EndDate >= newReservationEnd) ||
                                                                                      (r.StartDate >= newReservationStart && r.EndDate <= newReservationEnd)
                                                                                  ));

            if (overlapReservation != null)
            {
                Aircraft ac = _dataService.GetAircraftById(overlapReservation.AircraftId);
                ModelState.AddModelError(String.Empty,
                                         String.Format("Reservation conflicts with another reservation for {0} which starts at {1} and ends at {2}.\nPlease adjust your reservation times so there's no overlap.",
                                                       ac.RegistrationNumber,
                                                       overlapReservation.StartDate.ToString("yyyy-MM-dd hh:mm"),
                                                       overlapReservation.EndDate.ToString("yyyy-MM-dd hh:mm")));
            }

            return(ModelState.IsValid);
        }