Esempio n. 1
0
        public async Task <IActionResult> Edit(HallEditViewModel hallEditViewModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(hallEditViewModel));
            }

            await this.hallsService.EditAsync(hallEditViewModel);

            return(this.RedirectToAction("GetAll", "Halls", new { area = "Administration" }));
        }
Esempio n. 2
0
        public async Task CheckIfEditingHallReturnsNullReferenceException()
        {
            this.SeedDatabase();

            var hallEditViewModel = new HallEditViewModel
            {
                Id       = 3,
                Category = HallCategory.Small.ToString(),
            };

            var exception = await Assert
                            .ThrowsAsync <NullReferenceException>(async() => await this.hallsService.EditAsync(hallEditViewModel));

            Assert.Equal(string.Format(ExceptionMessages.HallNotFound, hallEditViewModel.Id), exception.Message);
        }
Esempio n. 3
0
        public async Task CheckEditingHallWithInvalidCategoryType()
        {
            this.SeedDatabase();

            var hallEditViewModel = new HallEditViewModel
            {
                Id       = this.firstHall.Id,
                Category = "Invalid category",
                Capacity = 10,
            };

            var exception = await Assert
                            .ThrowsAsync <ArgumentException>(async() => await this.hallsService.EditAsync(hallEditViewModel));

            Assert.Equal(string.Format(ExceptionMessages.InvalidHallCategoryType, hallEditViewModel.Category), exception.Message);
        }
Esempio n. 4
0
        public async Task CheckIfEditingHallWorksCorrectly()
        {
            this.SeedDatabase();

            var hallEditViewModel = new HallEditViewModel
            {
                Id       = this.firstHall.Id,
                Category = HallCategory.Medium.ToString(),
                Capacity = 35,
            };

            await this.hallsService.EditAsync(hallEditViewModel);

            Assert.Equal(hallEditViewModel.Category, this.firstHall.Category.ToString());
            Assert.Equal(hallEditViewModel.Capacity, this.firstHall.Capacity);
        }
        public async Task EditAsync(HallEditViewModel hallEditViewModel)
        {
            if (!Enum.TryParse(hallEditViewModel.Category, true, out HallCategory hallCategory))
            {
                throw new ArgumentException(
                          string.Format(ExceptionMessages.InvalidHallCategoryType, hallEditViewModel.Category));
            }

            var hall = await this.hallsRepository.All().FirstOrDefaultAsync(g => g.Id == hallEditViewModel.Id);

            if (hall == null)
            {
                throw new NullReferenceException(
                          string.Format(ExceptionMessages.HallNotFound, hallEditViewModel.Id));
            }

            hall.Category   = hallCategory;
            hall.Capacity   = hallEditViewModel.Capacity;
            hall.ModifiedOn = DateTime.UtcNow;

            this.hallsRepository.Update(hall);
            await this.hallsRepository.SaveChangesAsync();
        }