예제 #1
0
        public ActionResult PetGalleryCreate(PetGalleryViewModel model)
        {
            PetGallery newPhoto = new PetGallery();

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

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

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

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

                newPhoto.GalleryPhoto = data;
            }

            newPhoto.Comment = model.PhotoComment;
            newPhoto.PetID   = model.CurrentPetID;

            db.PetGallery.Add(newPhoto);
            db.SaveChanges();

            return(RedirectToAction("PetGallery", new { id = model.CurrentPetID }));
        }
예제 #2
0
        //-------------------------------------------------------------------------------
        //                                                PET GALLERY -- ADD PHOTO -- GET
        //-------------------------------------------------------------------------------
        //GET: Pet/PetGalleryCreate
        public ActionResult PetGalleryCreate(int?id)
        {
            PetGalleryViewModel PetG = new PetGalleryViewModel();

            PetG.CurrentPetID = db.Pets.Where(x => x.PetID == id)
                                .Select(x => x.PetID).First();

            return(View(PetG));
        }
예제 #3
0
        //===============================================================================
        //                                                           PET GALLERY STUFF!!!
        //===============================================================================
        public ActionResult PetGallery(int?id)
        {
            var ThisPetsName = db.Pets.Where(pn => pn.PetID == id)
                               .Select(pn => pn.PetName)
                               .FirstOrDefault();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            PetGalleryViewModel petGal = new PetGalleryViewModel();

            petGal.CurrentPetID = id;

            petGal.PetGalleryList = db.PetGallery.Where(x => x.PetID == id)
                                    .Select(n => new PetGalleryInfo
            {
                PetPicID = n.PetPicID,
                PetID    = n.PetID,
                Comment  = n.Comment
            }).ToList();

            ViewBag.ImageCount   = db.PetGallery.Where(x => x.PetID == id).Count();
            ViewBag.ThisPetID    = id;
            ViewBag.ThisPetsName = ThisPetsName;

            //---------------------------------------------------------------------------
            // 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(petGal));
        }