Esempio n. 1
0
        public RequestStatus GetCateringChoice(ref CateringChoice cateringChoice)
        {
            if (cateringChoice == null)
            {
                return RequestStatus.InvalidInput;
            }

            cateringChoice = CateringChoice.GetCateringChoice(cateringChoice.ID);

            return cateringChoice != null ? RequestStatus.Success : RequestStatus.InvalidInput;
        }
Esempio n. 2
0
        public RequestStatus ChangeStatus(CateringChoice updatedCateringChoice)
        {
            if (!string.IsNullOrWhiteSpace(updatedCateringChoice.Status))
            {
                if (updatedCateringChoice.Status.Equals("Approved"))
                {
                    this.Status = "Approved";
                    BookITContext.Db.SaveChanges();
                    return RequestStatus.Success;
                }

                return updatedCateringChoice.Status.Equals("Rejected") ? this.Remove() : RequestStatus.InvalidInput;
            }

            return RequestStatus.InvalidInput;
        }
Esempio n. 3
0
        public RequestStatus AddCateringToBooking(string token, CateringChoice cateringChoice, out Booking editedBooking)
        {
            try
            {
                editedBooking = null;

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

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

                if (p != null)
                {
                    if (p.ID.Equals(editedBooking.PersonID))
                    {
                        return editedBooking.AddCatering(cateringChoice);
                    }
                }
                return RequestStatus.AccessDenied;
            }

            catch (DbEntityValidationException e)
            {
                System.IO.StreamWriter file = new System.IO.StreamWriter(@"c:\RentItServices\RentIt12\Stuff\test.txt");
                foreach (var eve in e.EntityValidationErrors)
                {
                    file.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        file.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
                    }
                    file.Flush();
                }
                editedBooking = null;
                return RequestStatus.AccessDenied;
            }
        }
Esempio n. 4
0
        public RequestStatus RemoveCateringChoice(string token, CateringChoice cateringChoice, out Booking editedBooking)
        {
            editedBooking = null;

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

            var p = Person.GetByToken(token);
            var cc = CateringChoice.GetCateringChoice(cateringChoice.ID);
            if (cc == null)
            {
                return RequestStatus.InvalidInput;
            }

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

            var rs = cc.Remove();
            editedBooking = Booking.GetBookingByID(cateringChoice.ID);
            return rs;
        }
Esempio n. 5
0
        public RequestStatus ChangeTime(CateringChoice updatedCateringChoice)
        {
            if (updatedCateringChoice.Time >= this.Booking.StartTime
                && updatedCateringChoice.Time <= this.Booking.EndTime
                && Catering.IsAvailable(updatedCateringChoice.CateringID, updatedCateringChoice.Time))
            {
                this.Time = updatedCateringChoice.Time;
                BookITContext.Db.SaveChanges();
                return RequestStatus.Success;
            }

            return RequestStatus.InvalidInput;
        }
Esempio n. 6
0
        public RequestStatus AddCatering(CateringChoice choice)
        {
            if (this.StartTime <= choice.Time && choice.Time <= this.EndTime && Catering.IsAvailable(choice.CateringID, choice.Time) && choice.Amount >= 1)
            {
                if ((choice.Amount >= Configuration.CateringLimit && choice.Time.AddDays(-Configuration.DaysToPrepareBigCatering) > DateTime.Now)
                    || (choice.Time.AddDays(-Configuration.DaysToPrepareSmallCatering) > DateTime.Now))
                {
                    var cc = new CateringChoice
                        {
                            Amount = choice.Amount,
                            BookingID = this.ID,
                            Time = choice.Time,
                            Status = choice.Status ?? string.Empty,
                            CateringID = choice.CateringID,
                        };
                    BookITContext.Db.CateringChoices.Add(cc);
                    BookITContext.Db.SaveChanges();
                    return RequestStatus.Success;
                }

                return RequestStatus.InvalidInput;
            }

            return RequestStatus.InvalidInput;
        }