Пример #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            DAL.Pet pet = db.Pets.Find(id);
            db.Pets.Remove(pet);

            db.SaveChanges();

            return(RedirectToAction("ProfilePage", "Index"));
        }
Пример #2
0
        public void ItShouldMapTheExpectedValues(DAL.Pet pet, IMapper sut)
        {
            // Arrange
            var likeness = pet.AsSource()
                           .OfLikeness <Details.Model>()
                           .With(x => x.Kind).EqualsWhen((s, d) => s.Kind.ToString() == d.Kind)
                           .With(x => x.Status).EqualsWhen((s, d) => s.Status.ToString() == d.Status);

            // Act
            var result = sut.Map <DAL.Pet, Details.Model>(pet);

            // Assert
            likeness.ShouldEqual(result);
        }
Пример #3
0
        //===============================================================================
        //                                                              DELETE PET -- GET
        //===============================================================================
        // GET: Pets/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            DAL.Pet pet = db.Pets.Find(id);

            if (pet == null)
            {
                return(HttpNotFound());
            }

            return(View(pet));
        }
Пример #4
0
            private Task ToogleStatus(DAL.Pet pet)
            {
                var currentStatus = pet.Status;

                switch (currentStatus)
                {
                case DAL.PetStatus.Owned:
                    pet.Status = DAL.PetStatus.Lost;
                    return(_registryService.Add(pet));

                case DAL.PetStatus.Lost:
                    pet.Status = DAL.PetStatus.Owned;
                    return(_registryService.Remove(pet));

                default:
                    throw new InvalidOperationException($"Undefined pet status {currentStatus}.");
                }
            }
Пример #5
0
        //===============================================================================
        //              MY PET DETAILS -- private pet info -- for owners, selected carers
        //===============================================================================
        public ActionResult MyPetDetails(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            DAL.Pet pet = db.Pets.Find(id);

            if (pet == null)
            {
                return(HttpNotFound());
            }

            //---------------------------------------------------------------------------
            // testing to find this Pet's owner --
            //        to ONLY show details/appts/editPet buttons to the Pet's owner!
            // find this Pet's Owner's ID
            var thisPetsOwnersID = db.Pets.Where(p => p.PetID == id)
                                   .Select(poID => poID.PetOwnerID).FirstOrDefault();

            // now pull this Pet Owner's PetopiaUser ID
            var thisPetsOwnersPetopiaUserID = db.PetOwners.Where(pu => pu.PetOwnerID == thisPetsOwnersID)
                                              .Select(puID => puID.UserID).FirstOrDefault();

            // now pull this PetopiaUser's ASPNetIdentityID
            var thisPetsOwnersASPNetIdentityID = db.PetopiaUsers.Where(pu => pu.UserID == thisPetsOwnersPetopiaUserID)
                                                 .Select(aspnetID => aspnetID.ASPNetIdentityID)
                                                 .FirstOrDefault();

            // now pull the logged-in user's ID
            var loggedInUser = User.Identity.GetUserId();

            // so kinda backwards from the queries in the profile or care transaction controllers!
            ViewBag.thisPetsOwnersASPNetIdentityID = thisPetsOwnersASPNetIdentityID;
            ViewBag.loggedInUser = loggedInUser;

            //---------------------------------------------------------

            return(View(pet));
        }
Пример #6
0
        public ActionResult EditPet(PetPicViewModel model)
        {
            DAL.Pet pet = new DAL.Pet();

            if (ModelState.IsValid)
            {
                var identityID = User.Identity.GetUserId();

                var loggedID = db.PetopiaUsers.Where(x => x.ASPNetIdentityID == identityID)
                               .Select(x => x.UserID).First();

                int ownerID = db.PetOwners.Where(x => x.UserID == loggedID)
                              .Select(x => x.PetOwnerID).First();


                pet.PetOwnerID = ownerID;

                pet.PetName    = model.PetName;
                pet.Species    = model.Species;
                pet.Breed      = model.Breed;
                pet.Gender     = model.Gender;
                pet.Birthdate  = model.Birthdate;
                pet.PetCaption = model.PetCaption;
                pet.PetBio     = model.PetBio;

                pet.Weight                = model.Weight;
                pet.HealthConcerns        = model.HealthConcerns;
                pet.BehaviorConcerns      = model.BehaviorConcerns;
                pet.PetAccess             = model.PetAccess;
                pet.EmergencyContactName  = model.EmergencyContactName;
                pet.EmergencyContactPhone = model.EmergencyContactPhone;
                pet.NeedsDetails          = model.NeedsDetails;

                pet.PetID = model.PetID;

                // pet profile picture
                if (model.PetPhoto != null)
                {
                    if (model.PetPhoto.ContentLength > (4 * 1024 * 1024))
                    {
                        ModelState.AddModelError("CustomError", "Image can not be lager than 4MB.");
                        return(View(model));
                    }

                    if (!(model.PetPhoto.ContentType == "image/jpeg"))
                    {
                        ModelState.AddModelError("CustomError", "Image must be in jpeg format.");
                        return(View(model));
                    }

                    byte[] data = new byte[model.PetPhoto.ContentLength];

                    model.PetPhoto.InputStream.Read(data, 0, model.PetPhoto.ContentLength);

                    pet.PetPhoto = data;
                }
                else //If no pic was uploaded, we need to seed the current profile pic into our user
                {
                    pet.PetPhoto = db.Pets.Where(x => x.PetID == pet.PetID).Select(x => x.PetPhoto).FirstOrDefault();
                }
                //-----------------------------------------------------

                db.Entry(pet).State = EntityState.Modified;

                db.SaveChanges();


                return(RedirectToAction("PetProfile", new { id = pet.PetID }));
            }

            // pick list for rating -- like 1 thru 5
            ViewBag.PetOwnerID = new SelectList(db.PetOwners, "PetOwnerID", "AverageRating", pet.PetOwnerID);

            // boy-girl-altered pick-list
            ViewBag.GenderList = genderSelectList;

            return(View(model));
        }
Пример #7
0
        //===============================================================================
        //                                                                EDIT PET -- GET
        //===============================================================================
        // GET: Pets/EditPet/5
        public ActionResult EditPet(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            DAL.Pet pet = db.Pets.Find(id);

            if (pet == null)
            {
                return(HttpNotFound());
            }
            //---------------------------------------------------------
            PetPicViewModel model = new PetPicViewModel();

            model.PetName               = pet.PetName;
            model.Species               = pet.Species;
            model.Breed                 = pet.Breed;
            model.Gender                = pet.Gender;
            model.Birthdate             = pet.Birthdate;
            model.Weight                = pet.Weight;
            model.HealthConcerns        = pet.HealthConcerns;
            model.BehaviorConcerns      = pet.BehaviorConcerns;
            model.PetAccess             = pet.PetAccess;
            model.EmergencyContactName  = pet.EmergencyContactName;
            model.EmergencyContactPhone = pet.EmergencyContactPhone;
            model.NeedsDetails          = pet.NeedsDetails;
            model.PetCaption            = pet.PetCaption;
            model.PetBio                = pet.PetBio;
            model.PetID                 = pet.PetID;


            // pick-list for rating -- 1 thru 5
            ViewBag.PetOwnerID = new SelectList(db.PetOwners, "PetOwnerID", "AverageRating", pet.PetOwnerID);

            // boy-girl-altered pick-list
            ViewBag.GenderList = genderSelectList;

            //---------------------------------------------------------------------------
            // testing to find this Pet's owner --
            //        to ONLY show details/appts/editPet buttons to the Pet's owner!
            // find this Pet's Owner's ID
            var thisPetsOwnersID = db.Pets.Where(p => p.PetID == id)
                                   .Select(poID => poID.PetOwnerID).FirstOrDefault();

            // now pull this Pet Owner's PetopiaUser ID
            var thisPetsOwnersPetopiaUserID = db.PetOwners.Where(pu => pu.PetOwnerID == thisPetsOwnersID)
                                              .Select(puID => puID.UserID).FirstOrDefault();

            // now pull this PetopiaUser's ASPNetIdentityID
            var thisPetsOwnersASPNetIdentityID = db.PetopiaUsers.Where(pu => pu.UserID == thisPetsOwnersPetopiaUserID)
                                                 .Select(aspnetID => aspnetID.ASPNetIdentityID)
                                                 .FirstOrDefault();

            // now pull the logged-in user's ID
            var loggedInUser = User.Identity.GetUserId();

            // so kinda backwards from the queries in the profile or care transaction controllers!
            ViewBag.thisPetsOwnersASPNetIdentityID = thisPetsOwnersASPNetIdentityID;
            ViewBag.loggedInUser = loggedInUser;

            //---------------------------------------------------------------------------

            return(View(model));
        }