public bool IsUserBilledOwner(GroomBooking booking)
        {
            if (!IsUserOwner())
            {
                return(false);                //not valid because not an owner
            }
            ApplicationUser user = GetUser(); //get user

            //get the booking again
            //"trust, but verify"
            booking = db.GroomBookings.Find(booking.GroomBookingID);
            //get the owner and the pets they have
            Owner owner = db.Owners
                          .Include(o => o.GroomBookings)
                          .Where(o => o.OwnerID == user.Owner.OwnerID)
                          .FirstOrDefault();

            if (owner.GroomBookings.Contains(booking))
            {
                return(true);
            }


            return(false); //otherwise invalid
        }
Пример #2
0
        public ActionResult Show(int id)
        {
            GroomBooking booking = db.GroomBookings.Include(b => b.GroomServices).FirstOrDefault(b => b.GroomBookingID == id);

            Debug.WriteLine("Logged in user is billed owner " + UserManager.IsUserBilledOwner(booking));
            return(View(booking));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            GroomBooking groomBooking = db.GroomBookings.Find(id);

            db.GroomBookings.Remove(groomBooking);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: GroomBookings/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GroomBooking groomBooking = db.GroomBookings.Find(id);

            if (groomBooking == null)
            {
                return(HttpNotFound());
            }
            return(View(groomBooking));
        }
 public ActionResult Edit([Bind(Include = "GroomBookingID,GroomBookingDate,PetID,GroomerID,OwnerID,GroomServiceID")] GroomBooking groomBooking)
 {
     if (ModelState.IsValid)
     {
         groomBooking.GroomBookingPrice = db.GroomServices.SingleOrDefault(x => x.GroomServiceID == groomBooking.GroomServiceID).ServiceCost;
         db.Entry(groomBooking).State   = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.GroomerID      = new SelectList(db.Groomers, "GroomerID", "FirstName", groomBooking.GroomerID);
     ViewBag.GroomServiceID = new SelectList(db.GroomServices, "GroomServiceID", "ServiceName", groomBooking.GroomServiceID);
     ViewBag.OwnerID        = new SelectList(db.Owners, "OwnerID", "FirstName", groomBooking.OwnerID);
     ViewBag.PetID          = new SelectList(db.Pets, "PetId", "Name", groomBooking.PetID);
     return(View(groomBooking));
 }
        public ActionResult Update(int id, string BookingDate, string BookingTime, decimal BookingPrice, int PetID, string OwnerID, string GroomerID, int[] BookingServices)
        {
            GroomBooking booking = db
                                   .GroomBookings
                                   .Include(b => b.GroomServices)
                                   .FirstOrDefault(b => b.GroomBookingID == id);

            //remove any existing services attached to this booking
            foreach (var service in booking.GroomServices.ToList())
            {
                booking.GroomServices.Remove(service);
            }
            db.SaveChanges();

            //https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
            Debug.WriteLine(BookingDate + " " + BookingTime);
            booking.GroomBookingDate  = DateTime.ParseExact(BookingDate + " " + BookingTime, "yyyy-MM-dd Hmm", CultureInfo.InvariantCulture);
            booking.GroomBookingPrice = (int)(BookingPrice * 100);
            booking.PetID             = PetID;
            booking.OwnerID           = OwnerID;
            booking.GroomerID         = GroomerID;



            //update the booking
            db.SaveChanges();

            //Microsoft REALLY doesn't like it if you try to enumerate on a null list
            if (BookingServices != null)
            {
                if (BookingServices.Length > 0)
                {
                    //then re-add the services
                    booking.GroomServices = new List <GroomService>();
                    //then add services to that booking
                    foreach (int ServiceID in BookingServices)
                    {
                        //Debug.WriteLine("ServiceID is "+ServiceID);
                        GroomService service = db.GroomServices.Find(ServiceID);
                        //Debug.WriteLine("Service Name is "+service.ServiceName);
                        booking.GroomServices.Add(service);
                    }
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("List"));
        }
        // GET: GroomBookings/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GroomBooking groomBooking = db.GroomBookings.Find(id);

            if (groomBooking == null)
            {
                return(HttpNotFound());
            }
            ViewBag.GroomerID      = new SelectList(db.Groomers, "GroomerID", "FirstName", groomBooking.GroomerID);
            ViewBag.GroomServiceID = new SelectList(db.GroomServices, "GroomServiceID", "ServiceName", groomBooking.GroomServiceID);
            ViewBag.OwnerID        = new SelectList(db.Owners, "OwnerID", "FirstName", groomBooking.OwnerID);
            ViewBag.PetID          = new SelectList(db.Pets, "PetId", "Name", groomBooking.PetID);
            return(View(groomBooking));
        }
        public ActionResult Add(string BookingDate, string BookingTime, decimal BookingPrice, int PetID, string OwnerID, string GroomerID, int[] BookingServices)
        {
            GroomBooking newbooking = new GroomBooking();

            //https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
            Debug.WriteLine(BookingDate + " " + BookingTime);
            newbooking.GroomBookingDate  = DateTime.ParseExact(BookingDate + " " + BookingTime, "yyyy-MM-dd Hmm", CultureInfo.InvariantCulture);
            newbooking.GroomBookingPrice = (int)(BookingPrice * 100);
            newbooking.PetID             = PetID;
            newbooking.OwnerID           = OwnerID;
            newbooking.GroomerID         = GroomerID;

            //first add booking
            db.GroomBookings.Add(newbooking);
            db.SaveChanges();

            //Microsoft REALLY doesn't like it if you try to enumerate on a null list
            if (BookingServices != null)
            {
                if (BookingServices.Length > 0)
                {
                    newbooking.GroomServices = new List <GroomService>();
                    //then add services to that booking
                    foreach (int ServiceID in BookingServices.ToList())
                    {
                        //Debug.WriteLine("ServiceID is "+ServiceID);
                        GroomService service = db.GroomServices.Find(ServiceID);
                        //Debug.WriteLine("Service Name is "+service.ServiceName);
                        newbooking.GroomServices.Add(service);
                    }
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("List"));
        }
        public ActionResult Show(int id)
        {
            GroomBooking booking = db.GroomBookings.Include(b => b.GroomServices).FirstOrDefault(b => b.GroomBookingID == id);

            return(View(booking));
        }