예제 #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;
        }
예제 #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;
        }
예제 #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;
            }
        }
예제 #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;
        }
예제 #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;
        }
예제 #6
0
파일: Booking.cs 프로젝트: esfdk/itubs
        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;
        }