public ActionResult Edit(EditFoundPetBM bind)
        {
            string username = User.Identity.Name;

            var validImageTypes = new string[]
            {
                "image/gif",
                "image/jpeg",
                "image/pjpeg",
                "image/jpg",
                "image/png"
            };

            if (bind.Thumbnail != null && !validImageTypes.Contains(bind.Thumbnail.ContentType))
            {
                ModelState.AddModelError("Thumbnail", "Please choose either a GIF, JPG or PNG image.");
            }

            if (this.ModelState.IsValid && this.service.PetBelongsToUser(username, bind.Id) || User.IsInRole("Admin"))
            {
                try
                {
                    this.service.EditPet(bind);
                    return(RedirectToAction("profile", "users"));
                }
                catch (System.Web.HttpException e)
                {
                    ModelState.AddModelError("Thumbnail", e.Message);
                }
            }


            return(RedirectToAction("index", "home"));
        }
Exemple #2
0
        public void Edit_ShouldRedirectSuccessfully()
        {
            EditFoundPetBM bm = new EditFoundPetBM()
            {
                AnimalType = AnimalType.Other,

                Breed                  = "Edited Breed",
                Description            = "",
                DistinguishingFeatures = "",
                LastSeenLocation       = "West Park",
                LastSeenTime           = DateTime.Today,
                ActionTaken            = "nothing",
                Thumbnail              = null,
                Id = 1
            };

            this._controller.WithCallTo(c => c.Edit(bm)).ShouldRedirectToRoute("");
        }
Exemple #3
0
        public void Edit_ShouldEditSuccessfully()
        {
            EditFoundPetBM bm = new EditFoundPetBM()
            {
                AnimalType             = AnimalType.Other,
                Breed                  = "Edited Breed",
                Description            = "",
                DistinguishingFeatures = "",
                LastSeenLocation       = "West Park",
                LastSeenTime           = DateTime.Today,
                Thumbnail              = null,
                Id          = 1,
                ActionTaken = "Edited"
            };

            this._controller.Edit(bm);

            Assert.AreEqual("Edited", this._context.FoundPets.Find(1).ActionTaken);
        }
Exemple #4
0
        public void EditPet(EditFoundPetBM bind)
        {
            FoundPet foundPet = this.Context.FoundPets.Find(bind.Id);


            foundPet.AnimalType             = bind.AnimalType;
            foundPet.Breed                  = bind.Breed;
            foundPet.LastSeenLocation       = bind.LastSeenLocation;
            foundPet.LastSeenTime           = bind.LastSeenTime;
            foundPet.DistinguishingFeatures = bind.DistinguishingFeatures;
            foundPet.Description            = bind.Description;
            foundPet.ActionTaken            = bind.ActionTaken;

            if (bind.Thumbnail != null && bind.Thumbnail.ContentLength > 0)
            {
                var uploadDir = "~/Uploads/FoundPets";
                var imagePath = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath(uploadDir), bind.Thumbnail.FileName);
                var imageUrl  = uploadDir + "/" + bind.Thumbnail.FileName;
                bind.Thumbnail.SaveAs(imagePath);
                foundPet.ThumbnailUrl = imageUrl.Remove(0, 1);
            }

            this.Context.SaveChanges();
        }