コード例 #1
0
        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));
        }
コード例 #2
0
        /// <summary>
        /// Opening Page for Entering New Recipes
        /// </summary>
        public async Task <IActionResult> Add()
        {
            ViewData["Title"]    = _localizer["PageTitleAdd"];
            ViewData["PageDesc"] = _localizer["PageDescAdd"];

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

            var getVarietiesQuery = _queryFactory.CreateVarietiesQuery();
            var vList             = await getVarietiesQuery.ExecuteAsync().ConfigureAwait(false);

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

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

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


            var addRecipeModel = _modelFactory.CreateAddRecipeModel(cList, vList, yList, uomSugarList, uomTempList);

            addRecipeModel.User = await UserManagerAgent.GetUserAsync(User).ConfigureAwait(false);

            return(View(addRecipeModel));
        }
コード例 #3
0
        public async Task <IActionResult> Index()
        {
            ViewData["Title"]    = _localizer["PageTitle"];
            ViewData["PageDesc"] = _localizer["PageDesc"];

            var submittedBy = await UserManagerAgent.GetUserAsync(User).ConfigureAwait(false);

            var model = _modelFactory.CreateContactModel();

            model.User = submittedBy;
            return(View(model));
        }
コード例 #4
0
        public async Task <IActionResult> EditBatch(int id)
        {
            ViewData["Title"]    = _localizer["PageTitleDetails"];
            ViewData["PageDesc"] = _localizer["PageDescDetails"];

            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 cultureQuery = _maloCultureQueryFactory.CreateMaloCulturesQuery();
            var cultureList  = await cultureQuery.ExecuteAsync().ConfigureAwait(false);

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

            var batchQuery = _journalQueryFactory.CreateBatchesQuery();
            var batchDto   = await batchQuery.ExecuteAsync(id).ConfigureAwait(false);

            var entriesQuery = _journalQueryFactory.CreateBatchEntriesQuery();
            var entriesDto   = await entriesQuery.ExecuteByFKAsync(id).ConfigureAwait(true);

            var batchEntriesDto = entriesDto
                                  .OrderByDescending(e => e.ActionDateTime)
                                  .ThenByDescending(e => e.EntryDateTime).ToList();

            var model = _modelFactory.CreateBatchViewModel(batchDto, batchEntriesDto, vList, cList, yList, cultureList, uomVolumeList, uomSugarList, uomTempList);

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

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

            return(View("UpdateBatch", model));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        /// <summary>
        /// Main Landing Page for Journals
        /// </summary>
        public async Task <IActionResult> Index()
        {
            ViewData["Title"]    = _localizer["PageTitle"];
            ViewData["PageDesc"] = _localizer["PageDesc"];

            var submittedBy = await UserManagerAgent.GetUserAsync(User).ConfigureAwait(false);

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

            var entriesQuery = _journalQueryFactory.CreateBatchEntriesQuery();

            var getBatchesQuery = _journalQueryFactory.CreateBatchesQuery();
            var batchesDto      = await getBatchesQuery.ExecuteByUserAsync(submittedBy.Id).ConfigureAwait(false);

            foreach (var b in batchesDto)
            {
                var entriesDto = await entriesQuery.ExecuteByFKAsync(b.Id.Value).ConfigureAwait(true);

                b.Entries.AddRange(entriesDto.OrderByDescending(e => e.ActionDateTime).ThenByDescending(e => e.EntryDateTime));
                b.Variety.Literal = vList.FirstOrDefault(v => v.Id == b.Variety.Id).Literal;
            }

            var journalModel = _modelFactory.CreateJournalModel();

            var batchItemsModel = _modelFactory.BuildBatchListItemModels(batchesDto);

            journalModel.Batches = batchItemsModel
                                   .OrderBy(r => r.BatchComplete)
                                   .ThenByDescending(r => r.Vintage)
                                   .ThenBy(r => r.Variety);

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

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

            return(View(journalModel));
        }
コード例 #7
0
        public async Task <IActionResult> Add(AddRecipeViewModel model)
        {
            ViewData["Title"]    = _localizer["PageTitle"];
            ViewData["PageDesc"] = _localizer["PageDesc"];

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

            var getVarietiesQuery = _queryFactory.CreateVarietiesQuery();
            var vList             = await getVarietiesQuery.ExecuteAsync().ConfigureAwait(false);

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

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

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

            // must be logged in to continue
            var submittedBy = await UserManagerAgent.GetUserAsync(User).ConfigureAwait(false);

            if (submittedBy == null)
            {
                var addRecipeModel = _modelFactory.CreateAddRecipeModel(cList, vList, yList, uomSugarList, uomTempList, model);
                Warning(_localizer["NoLogIn"], false);
                return(View(addRecipeModel));
            }

            // using model validation attributes, if model state says errors do nothing
            if (!ModelState.IsValid)
            {
                var addRecipeModel = _modelFactory.CreateAddRecipeModel(cList, vList, yList, uomSugarList, uomTempList, model);
                Warning(_localizer["AddGeneralError"], true);
                return(View(addRecipeModel));
            }

            ICode variety = null;

            if (int.TryParse(model?.VarietyId, out int varietyId))
            {
                variety = vList.FirstOrDefault(c => c.Id == varietyId);
            }

            ICode category = null;

            if (variety != null && variety.ParentId.HasValue)
            {
                category = cList.FirstOrDefault(c => c.Id == variety.ParentId.Value);
            }

            YeastDto yeast = null;

            if (int.TryParse(model?.YeastId, out int yeastId))
            {
                yeast = yList.FirstOrDefault(y => y.Id == yeastId);
            }

            Business.Journal.Dto.TargetDto target = null;

            if (model.Target.HasTargetData())
            {
                target = new Business.Journal.Dto.TargetDto
                {
                    EndSugar   = model.Target.EndingSugar,
                    pH         = model.Target.pH,
                    StartSugar = model.Target.StartingSugar,
                    TA         = model.Target.TA,
                    Temp       = model.Target.FermentationTemp,
                };

                if (model.Target.StartSugarUOM.HasValue)
                {
                    target.StartSugarUom = uomSugarList.FirstOrDefault(u => u.Id == model.Target.StartSugarUOM.Value);
                }
                if (model.Target.EndSugarUOM.HasValue)
                {
                    target.EndSugarUom = uomSugarList.FirstOrDefault(u => u.Id == model.Target.EndSugarUOM.Value);
                }
                if (model.Target.TempUOM.HasValue)
                {
                    target.TempUom = uomTempList.FirstOrDefault(u => u.Id == model.Target.TempUOM.Value);
                }
            }
            // convert add model to recipe dto
            var recipeDto = new Business.Recipe.Dto.RecipeDto
            {
                Description   = model.Description,
                Enabled       = false,
                Hits          = 0,
                Ingredients   = model.Ingredients,
                Instructions  = model.Instructions,
                NeedsApproved = true,
                Rating        = null,
                SubmittedBy   = submittedBy.Id,
                Target        = target,
                Title         = model.Title,
                Yeast         = yeast,
                Variety       = variety
            };

            //recipeDto.Id = 1;  // for testing only
            var updateRecipesCommand = _commandsFactory.CreateRecipesCommand();

            recipeDto = await updateRecipesCommand.AddAsync(recipeDto).ConfigureAwait(false);


            // process uploaded files
            if (model.Images != null)
            {
                var           updateImageCommand = _commandsFactory.CreateImageCommand();
                long          maxFileSizeBytes   = 512000;
                List <string> allowedExtensions  = new List <string> {
                    ".jpg", ".jpeg", ".bmp", ".png", ".gif"
                };
                int maxUploads  = 4;
                int uploadCount = 1;

                foreach (FormFile file in model.Images)
                {
                    // Max File Size per Image: 500 KB
                    if (file.Length > maxFileSizeBytes)
                    {
                        continue;
                    }
                    // Allowed Image Extensions: .jpg | .gif | .bmp | .jpeg | .png ONLY
                    var ext = Path.GetExtension(file.FileName);
                    if (!allowedExtensions.Any(e => e.Equals(ext, StringComparison.OrdinalIgnoreCase)))
                    {
                        continue;
                    }
                    // Pictures Max 4
                    if (uploadCount > maxUploads)
                    {
                        break;
                    }

                    using MemoryStream ms = new MemoryStream();
                    file.OpenReadStream().CopyTo(ms);
                    var imageData = await ResizeImage(ms.ToArray(), 360, 480).ConfigureAwait(false);

                    var thumbData = await ResizeImage(ms.ToArray(), 100, 150).ConfigureAwait(false);

                    var imageDto = _dtoFactory.CreateNewImageFile(recipeDto.Id, file.FileName, file.Name, imageData, thumbData, file.Length, file.ContentType);
                    await updateImageCommand.AddAsync(imageDto).ConfigureAwait(false);

                    uploadCount++;
                }
            }

            var subjectLine = "There is a new recipe is in the approval queue.";
            var bodyContent = "A new recipe has been submitted and needs approved.";

            // notify admin that new recipe is in the approval queue
            await _emailAgent.SendEmailAsync(_appSettings.SMTP.FromEmail, _appSettings.SMTP.FromEmail, _appSettings.SMTP.AdminEmail,
                                             subjectLine, bodyContent, false, null).ConfigureAwait(false);

            // tell user good job and clear or go to thank you page
            ModelState.Clear();
            var addNewRecipeModel = _modelFactory.CreateAddRecipeModel(cList, vList, yList, uomSugarList, uomTempList);

            addNewRecipeModel.User = submittedBy;

            Success(_localizer["AddSuccess"], true);

            return(View(addNewRecipeModel));
        }
コード例 #8
0
        public async Task <IActionResult> Add(BatchViewModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            ViewData["Title"]    = _localizer["PageTitle"];
            ViewData["PageDesc"] = _localizer["PageDesc"];

            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);

            // must be logged in to continue
            var submittedBy = await UserManagerAgent.GetUserAsync(User).ConfigureAwait(false);

            if (submittedBy == null)
            {
                var addModel = _modelFactory.CreateBatchViewModel(null, null, vList, cList, yList, null, uomVolumeList, uomSugarList, uomTempList);
                Warning(_localizer["AddGeneralError"], false);
                return(View(addModel));
            }

            // using model validation attributes, if model state says errors do nothing
            if (!ModelState.IsValid)
            {
                var addModel = _modelFactory.CreateBatchViewModel(null, null, vList, cList, yList, null, uomVolumeList, uomSugarList, uomTempList);
                Warning(_localizer["AddGeneralError"], true);
                return(View(addModel));
            }

            TargetDto targetDto;

            if (model.Target.Id.HasValue)
            {
                var targetQuery = _journalQueryFactory.CreateTargetsQuery();
                targetDto = targetQuery.Execute(model.Target.Id.Value);
            }
            else
            {
                targetDto = new TargetDto();
            }

            if (model.Target.HasTargetData())
            {
                // convert add model to batch and target dto
                targetDto.Temp       = model.Target.FermentationTemp;
                targetDto.pH         = model.Target.pH;
                targetDto.TA         = model.Target.TA;
                targetDto.StartSugar = model.Target.StartingSugar;
                targetDto.EndSugar   = model.Target.EndingSugar;

                if (model.Target.TempUOM.HasValue)
                {
                    targetDto.TempUom = new UnitOfMeasure {
                        Id = model.Target.TempUOM.Value
                    }
                }
                ;
                if (model.Target.StartSugarUOM.HasValue)
                {
                    targetDto.StartSugarUom = new UnitOfMeasure {
                        Id = model.Target.StartSugarUOM.Value
                    }
                }
                ;
                if (model.Target.EndSugarUOM.HasValue)
                {
                    targetDto.EndSugarUom = new UnitOfMeasure {
                        Id = model.Target.EndSugarUOM.Value
                    }
                }
                ;

                var updateTargetCommand = _journalCommandFactory.CreateTargetsCommand();
                if (targetDto.Id.HasValue)
                {
                    targetDto = await updateTargetCommand.UpdateAsync(targetDto).ConfigureAwait(false);
                }
                else
                {
                    targetDto = await updateTargetCommand.AddAsync(targetDto).ConfigureAwait(false);
                }
            }

            var batchDto = new BatchDto
            {
                Description = model.Description,
                Vintage     = model.Vintage,
                Volume      = model.Volume,
                Complete    = false,
                SubmittedBy = submittedBy?.Id,
                Title       = model.Title,
                Yeast       = yList.FirstOrDefault(y => y.Id == model.YeastId.Value),
                RecipeId    = model.RecipeId,
                Target      = targetDto,
                VolumeUom   = new UnitOfMeasure {
                    Id = model.VolumeUOM.Value
                },
                Variety = new Code {
                    Id = model.VarietyId.Value
                }
            };

            var updateBatchCommand = _journalCommandFactory.CreateBatchesCommand();
            await updateBatchCommand.AddAsync(batchDto).ConfigureAwait(false);

            // tell user good job and clear or go to thank you page
            ModelState.Clear();
            var addBatchModel = _modelFactory.CreateBatchViewModel(null, null, vList, cList, yList, null, uomVolumeList, uomSugarList, uomTempList);

            Success(_localizer["AddSuccess"], true);

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

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

            return(View(addBatchModel));
        }