コード例 #1
0
        public async Task <IActionResult> Edit(int id)
        {
            bool isSuplementExistingById = await this.supplementService.IsSupplementExistingById(id, false);

            if (!isSuplementExistingById)
            {
                TempData.AddErrorMessage(string.Format(EntityNotFound, SupplementEntity));

                return(this.RedirectToSupplementsIndex(false));
            }

            SupplementServiceModel supplement = await this.managerSupplementService.GetEditModelAsync(id);

            SupplementFormViewModel model = new SupplementFormViewModel()
            {
                Name           = supplement.Name,
                Description    = supplement.Description,
                Quantity       = supplement.Quantity,
                Price          = supplement.Price,
                BestBeforeDate = supplement.BestBeforeDate,

                SubcategoryId  = supplement.SubcategoryId,
                ManufacturerId = supplement.ManufacturerId,
            };

            int categoryId = await this.subcategoryService.GetCategoryIdBySubcategoryId(supplement.SubcategoryId);

            await PrepareModelToReturn(categoryId, model);

            ViewData["CategoryId"] = categoryId;

            return(View(model));
        }
コード例 #2
0
        public async Task GetEditModelAsync_WithSupplementId_ShouldReturnValidServiceModel()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            DatabaseHelper.SeedData(database);

            IManagerSupplementService managerSupplementService = new ManagerSupplementService(database);

            // Act
            SupplementServiceModel result = await managerSupplementService.GetEditModelAsync(firstNotDeletedSupplementId);

            // Assert
            result.Name.Should().Be(firstNotDeletedSupplementName);
        }