public void ShouldNotBeAbleToEditIfNotOwner()
        {
            this.createDog.Name = "Balkan";

            this.dogsController.New(createDog);

            var fakeFaker = new User
            {
                FirstName = "Faker"
            };

            this.context.Users.Add(fakeFaker);

            this.context.SaveChanges();

            var dogId = this.context.Dogs.Single(d => d.Name == "Balkan").Id;

            this.context.Dogs.Single(d => d.Id == dogId).Owner = fakeFaker;

            this.context.SaveChanges();

            var model = new EditDogViewModel
            {
                Id   = dogId,
                Name = "Zofran"
            };

            var result = this.dogsController.Edit(model) as RedirectToActionResult;

            Assert.AreEqual("Index", result.ActionName);

            Assert.AreEqual("Balkan", this.context.Dogs.Single(d => d.Id == dogId).Name);
        }
        public IActionResult Edit(Guid id)
        {
            var dog = new Dog();


            dog = this.context.Dogs.Single(d => d.Id == id);

            if (dog.OwnerId != this.userManager.GetUserId(User))
            {
                return(RedirectToAction("Index", "Home"));
            }


            var result = new EditDogViewModel
            {
                Name          = dog.Name,
                Gender        = dog.Gender,
                BirthDate     = dog.BirthDate,
                Province      = dog.Province,
                IsVaccinated  = dog.IsVaccinated,
                IsDisinfected = dog.IsDisinfected,
                IsCastrated   = dog.IsCastrated,
                OwnerNotes    = dog.OwnerNotes,
                Breed         = dog.Breed
            };

            return(View(result));
        }
Beispiel #3
0
        public void PersistDog(EditDogViewModel dog)
        {
            var data = _animalService.GetAnimalById(dog.Id) as Dog ?? new Dog();

            data.IsADrooler = dog.Drools;
            data.Name       = dog.Name;
            AssignOwner(dog.Owner, data);
            _animalService.Persist(data);
        }
        public void EditShouldWorkCorrectly()
        {
            this.createDog.Name     = "Anastasya";
            this.createDog.Province = Province.Montana;

            this.dogsController.New(this.createDog);

            var dog = this.context.Dogs.Single(d => d.Name == "Anastasya");

            var model = new EditDogViewModel
            {
                Id       = dog.Id,
                Name     = "KOlyo",
                Province = dog.Province
            };

            this.dogsController.Edit(model);

            Assert.AreEqual("KOlyo", dog.Name);

            Assert.AreEqual(Province.Montana, dog.Province);
        }
        public IActionResult Edit(EditDogViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            else
            {
                var dog = this.context.Dogs.Single(d => d.Id == model.Id);

                if (dog.OwnerId != this.userManager.GetUserId(User))
                {
                    return(RedirectToAction("Index", "Home"));
                }

                dog.Name = model.Name;

                dog.Gender = model.Gender;

                dog.BirthDate = model.BirthDate;

                dog.Province = model.Province;

                dog.IsVaccinated = model.IsVaccinated;

                dog.IsDisinfected = model.IsDisinfected;

                dog.IsCastrated = model.IsCastrated;

                dog.OwnerNotes = model.OwnerNotes;

                dog.Breed = model.Breed;

                context.SaveChanges();

                return(RedirectToAction("Dog", "Dogs", new { Id = model.Id }));
            }
        }
 public IActionResult PersistDog([FromForm] EditDogViewModel animal)
 {
     _translationService.PersistDog(animal);
     return(RedirectToAction(nameof(Index)));
 }