Пример #1
0
 public static bool IsBookingTimeValid(EquipmentChoice ec)
 {
     return ec.StartTime < ec.EndTime
                        && ec.StartTime.Hour >= Configuration.EarliestBooking.Hour
                        && ec.EndTime.Hour <= Configuration.LatestBooking.Hour
                        && ec.StartTime.Date.Equals(ec.EndTime.Date);
 }
Пример #2
0
 public static List<EquipmentChoice> OverlappingBookings(EquipmentChoice ec)
 {
     return
         All.Where(
             e =>
             e.EquipmentID == ec.EquipmentID
             &&
             ((e.StartTime <= ec.StartTime && e.EndTime > ec.StartTime)      /* Any starting before or same time as booking &
                                                                              * ends after start time of booking. */
              || (e.StartTime >= ec.StartTime && e.EndTime <= ec.EndTime)    /* Any starting after or same time as booking &
                                                                              * ends after or same time as booking. */
              || (e.StartTime <= ec.StartTime && e.EndTime >= ec.EndTime)    /* Any starting before or same time as booking &
                                                                              * ends same time or after booking. */
              || (e.StartTime >= ec.StartTime && e.StartTime < ec.EndTime))) /* Any starting after or same time as booking &
                                                                              * starting before end time of booking. */
             .ToList();
 }
Пример #3
0
        public RequestStatus AddEquipmentToBooking(string token, EquipmentChoice equipmentChoice, out Booking editedBooking)
        {
            editedBooking = null;

            if (string.IsNullOrWhiteSpace(token) || equipmentChoice == null)
            {
                return RequestStatus.InvalidInput;
            }

            var p = Person.GetByToken(token);
            var b = Booking.GetBookingByID(equipmentChoice.BookingID);
            if (b == null)
            {
                return RequestStatus.InvalidInput;
            }

            if (p == null || (!p.IsAdmin() && p.ID != b.PersonID))
            {
                return RequestStatus.AccessDenied;
            }

            editedBooking = Booking.GetBookingByID(equipmentChoice.BookingID);
            return editedBooking != null ? editedBooking.AddEquipment(equipmentChoice) : RequestStatus.InvalidInput;
        }
Пример #4
0
        public RequestStatus RemoveEquipmentChoice(string token, EquipmentChoice equipmentChoice, out Booking editedBooking)
        {
            editedBooking = null;

            if (string.IsNullOrWhiteSpace(token) || equipmentChoice == null)
            {
                return RequestStatus.InvalidInput;
            }

            var p = Person.GetByToken(token);
            var ec = EquipmentChoice.GetEquipmentChoiceByID(equipmentChoice.ID);
            if (ec == null)
            {
                return RequestStatus.InvalidInput;
            }

            if (p == null || (!p.IsAdmin() && p.ID != ec.Booking.PersonID))
            {
                return RequestStatus.AccessDenied;
            }

            var rs = ec.Remove();
            editedBooking = Booking.GetBookingByID(equipmentChoice.BookingID);
            return rs;
        }
Пример #5
0
        public RequestStatus ChangeTime(EquipmentChoice updatedChoice)
        {
            var overlapping = OverlappingBookings(updatedChoice);
            if (overlapping.All(ec => ec.BookingID == this.BookingID)
                && this.Booking.StartTime <= updatedChoice.StartTime
                && this.Booking.EndTime >= updatedChoice.EndTime)
            {
                if (overlapping.Count == 0
                    || (overlapping.Count == 1 && overlapping.First().ID == this.ID))
                {
                    this.StartTime = updatedChoice.StartTime;
                    this.EndTime = updatedChoice.EndTime;
                    BookITContext.Db.SaveChanges();
                    return RequestStatus.Success;
                }

                if (overlapping.All(choice => choice.Booking.PersonID == this.Booking.PersonID))
                {
                    var first = overlapping.First();
                    first.EndTime = updatedChoice.EndTime;
                    first.StartTime = updatedChoice.StartTime;
                    foreach (var a in overlapping.Where(o => o.ID != first.ID))
                    {
                        BookITContext.Db.EquipmentChoices.Remove(a);
                    }

                    BookITContext.Db.SaveChanges();
                }
            }

            return RequestStatus.InvalidInput;
        }
Пример #6
0
        public RequestStatus GetEquipmentChoice(ref EquipmentChoice equipmentChoice)
        {
            if (equipmentChoice == null)
            {
                return RequestStatus.InvalidInput;
            }

            equipmentChoice = EquipmentChoice.GetEquipmentChoiceByID(equipmentChoice.ID);

            return equipmentChoice != null ? RequestStatus.Success : RequestStatus.InvalidInput;
        }
Пример #7
0
        public RequestStatus AddEquipment(EquipmentChoice choice)
        {
            var overlapping = EquipmentChoice.OverlappingBookings(choice);
            if (EquipmentChoice.IsBookingTimeValid(choice) && overlapping.Count == 0
                && choice.StartTime >= this.StartTime && choice.EndTime <= this.EndTime)
            {
                BookITContext.Db.EquipmentChoices.Add(
                    new EquipmentChoice
                        {
                            BookingID = choice.BookingID,
                            EndTime = choice.EndTime,
                            StartTime = choice.StartTime,
                            EquipmentID = choice.EquipmentID
                        });
                BookITContext.Db.SaveChanges();
                return RequestStatus.Success;
            }

            return RequestStatus.InvalidInput;
        }