public async Task <IActionResult> Add()
        {
            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);

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

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

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

            return(View(addBatchModel));
        }
Beispiel #2
0
        public async Task <IActionResult> UpdateBatchAsync(int id, [FromBody] BatchUpdateViewModel batch)
        {
            try
            {
                if (batch == null)
                {
                    return(NoContent());
                }

                var qry = _queryFactory.CreateBatchesQuery();
                var dto = await qry.ExecuteAsync(id).ConfigureAwait(false);

                if (dto == null)
                {
                    return(NotFound());
                }

                dto.Description   = batch.Description;
                dto.Title         = batch.Title;
                dto.Vintage       = batch.Vintage;
                dto.Volume        = batch.Volume;
                dto.MaloCultureId = batch.MaloCultureId;

                if (batch.YeastId.HasValue)
                {
                    if (dto.Yeast == null)
                    {
                        dto.Yeast = new YeastDto {
                            Id = batch.YeastId.Value
                        }
                    }
                    ;
                    else
                    {
                        dto.Yeast.Id = batch.YeastId.Value;
                    }
                }


                if (batch.VarietyId.HasValue)
                {
                    if (dto.Variety == null)
                    {
                        dto.Variety = new Code();
                    }
                    if (dto.Variety.Id != batch.VarietyId.Value)
                    {
                        dto.Variety.Id = batch.VarietyId.Value;
                        dto.RecipeId   = null;
                    }
                }

                if (batch.VolumeUOM.HasValue)
                {
                    dto.VolumeUom = new UnitOfMeasure {
                        Id = batch.VolumeUOM.Value
                    }
                }
                ;

                var cmd      = _commandsFactory.CreateBatchesCommand();
                var batchDto = await cmd.UpdateAsync(dto).ConfigureAwait(false);

                var model = _modelFactory.CreateBatchViewModel(batchDto);

                return(Ok(model));
            }
            catch (Exception)
            {
                return(StatusCode(500));

                throw;
            }
        }