Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, EditPetInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                var breeds = this.breedsService.GetAll <BreedDropDownViewModel>();
                input.Breeds = breeds;
                return(this.View(input));
            }

            await this.petsService.UpdateAsync(id, input);

            return(this.RedirectToAction(nameof(this.ViewPetInfo), new { id }));
        }
Exemplo n.º 2
0
        public async Task EditPet(EditPetInputModel model)
        {
            var pet = await this.db.Pets.Include(p => p.Owner).FirstOrDefaultAsync(p => p.PetId == model.PetId);

            if (pet == null)
            {
                throw new ArgumentException("Pet id is invalid!");
            }

            pet.Name = model.Name;
            pet.Age  = model.Age;
            await this.db.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async Task <IActionResult> EditPet(EditPetInputModel model)
        {
            try
            {
                await this.petsService.EditPet(model);

                return(Ok());
            }
            catch (ArgumentException e)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 4
0
        public async Task UpdateAsync(int id, EditPetInputModel input)
        {
            var pet = this.petsRepo.All().FirstOrDefault(x => x.Id == id);

            pet.Name          = input.Name;
            pet.BirthDate     = input.BirthDate;
            pet.TypeOfPet     = input.TypeOfPet;
            pet.BreedId       = input.BreedId;
            pet.Description   = input.Description;
            pet.Sex           = input.Sex;
            pet.StartOfPeriod = input.StartOfPeriod;
            pet.EndOfPeriod   = input.EndOfPeriod;

            await this.petsRepo.SaveChangesAsync();
        }
Exemplo n.º 5
0
        public async Task <string> GetPet(string petId)
        {
            var pet = await this.db.Pets.FirstOrDefaultAsync(p => p.PetId == petId);

            if (pet == null)
            {
                throw new ArgumentException("Pet id is invalid!");
            }

            var viewModel = new EditPetInputModel()
            {
                Name    = pet.Name,
                Age     = pet.Age,
                PetId   = pet.PetId,
                OwnerId = pet.OwnerId,
            };

            var json = JsonConvert.SerializeObject(pet);

            return(json);
        }