public async Task <IActionResult> AddFromRecipe(int?recipeId, int?yeastId, int?varietyId, int?targetId)
        {
            ViewData["Title"]    = _localizer["PageTitleAdd"];
            ViewData["PageDesc"] = _localizer["PageDescAdd"];

            var batchTempQuery = _journalQueryFactory.CreateBatchTempUOMQuery();
            var uomTempList    = await batchTempQuery.ExecuteAsync().ConfigureAwait(false);

            var batchSugarQuery = _journalQueryFactory.CreateBatchSugarUOMQuery();
            var uomSugarList    = await batchSugarQuery.ExecuteAsync().ConfigureAwait(false);

            var batchVolumeQuery = _journalQueryFactory.CreateBatchVolumeUOMQuery();
            var uomVolumeList    = await batchVolumeQuery.ExecuteAsync().ConfigureAwait(false);

            var getCategoriesQuery = _recipeQueryFactory.CreateCategoriesQuery();
            var cList = await getCategoriesQuery.ExecuteAsync().ConfigureAwait(false);

            var varietiesQuery = _recipeQueryFactory.CreateVarietiesQuery();
            var vList          = await varietiesQuery.ExecuteAsync().ConfigureAwait(false);

            var getYeastQuery = _yeastQueryFactory.CreateYeastsQuery();
            var yList         = await getYeastQuery.ExecuteAsync().ConfigureAwait(false);

            BatchDto batch = new BatchDto();

            if (targetId.HasValue)
            {
                var getTargetsQuery = _journalQueryFactory.CreateTargetsQuery();
                batch.Target = getTargetsQuery.Execute(targetId.Value);
            }

            var addBatchModel = _modelFactory.CreateBatchViewModel(batch, null, vList, cList, yList, null, uomVolumeList, uomSugarList, uomTempList);

            addBatchModel.VarietyId = varietyId;
            addBatchModel.RecipeId  = recipeId;
            addBatchModel.YeastId   = yeastId;

            // validate with User (ApplicationUser)
            var appUser = await UserManagerAgent.GetUserAsync(User).ConfigureAwait(false);

            addBatchModel.BatchJwt = await CreateJwtTokenAsync(appUser, 15).ConfigureAwait(false);

            return(View("Add", addBatchModel));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> EditRecipe(int Id)
        {
            ViewData["Title"] = "Edit a Recipe";

            var recipeQry = _recipeQueryFactory.CreateRecipesQuery();
            var dto       = await recipeQry.ExecuteAsync(Id).ConfigureAwait(false);

            if (dto.Target != null)
            {
                var targetQry = _journalQueryFactory.CreateTargetsQuery();
                var targetDto = await targetQry.ExecuteAsync(dto.Target.Id.Value).ConfigureAwait(false);

                dto.Target = targetDto;
            }

            var model = _modelFactory.CreateRecipeViewModel(dto);

            var user = await UserManagerAgent.FindByIdAsync(dto.SubmittedBy).ConfigureAwait(false);

            model.SubmittedBy = string.Concat(user.FirstName, " ", user.LastName, " (", user.Email, ")");

            return(View("UpdateRecipe", model));
        }