public async Task UpdateAsync(YeastDto yeastDto)
        {
            await _client.MapAsync <YeastDto>(d => d.Properties(p => p
                                                                .String(s => s.Name(n => n.Name).Analyzer("autocomplete"))
                                                                .String(s => s.Name(n => n.ProductCode).Analyzer("autocomplete"))
                                                                ));

            await _client.IndexAsync(yeastDto);
        }
Esempio n. 2
0
        public async Task UpdateAsync(YeastDto yeastDto)
        {
            var yeast = AutoMapper.Mapper.Map <YeastDto, Yeast>(yeastDto);
            await _yeastRepository.UpdateAsync(yeast);

            var result = await _yeastRepository.GetSingleAsync(yeastDto.Id);

            var mappedResult = AutoMapper.Mapper.Map <Yeast, YeastDto>(result);
            await _yeastElasticsearch.UpdateAsync(mappedResult);
        }
        public async Task <IHttpActionResult> PostYeast(YeastDto yeastDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _yeastService.AddAsync(yeastDto);

            return(CreatedAtRoute("DefaultApi", new { controller = "yeasts", }, result));
        }
Esempio n. 4
0
        public async Task <YeastDto> AddAsync(YeastDto yeastDto)
        {
            var yeast = Mapper.Map <YeastDto, Yeast>(yeastDto);
            await _yeastRepository.AddAsync(yeast);

            var result = await _yeastRepository.GetSingleAsync(yeast.YeastId, "Supplier");

            var mappedResult = Mapper.Map <Yeast, YeastDto>(result);
            await _yeastElasticsearch.UpdateAsync(mappedResult);

            return(mappedResult);
        }
Esempio n. 5
0
        public async Task <YeastDto> AddAsync(YeastDto yeastDto)
        {
            var yeast = AutoMapper.Mapper.Map <YeastDto, Yeast>(yeastDto);
            await _yeastRepository.AddAsync(yeast);

            _logger.LogInformation($"YeastId: {yeast.YeastId}");
            var result = await _yeastRepository.GetSingleAsync(yeast.YeastId);

            var mappedResult = AutoMapper.Mapper.Map <Yeast, YeastDto>(result);
            await _yeastElasticsearch.UpdateAsync(mappedResult);

            return(mappedResult);
        }
Esempio n. 6
0
        public async Task <IActionResult> PostYeast([FromBody] YeastDto yeastDto)
        {
            if (yeastDto == null)
            {
                _logger.LogInformation("YEASTDTO NULL");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _yeastService.AddAsync(yeastDto);

            return(CreatedAtRoute(new { controller = "yeasts", }, result));
        }
Esempio n. 7
0
        public async Task <IActionResult> PutYeast(int id, [FromBody] YeastDto yeastDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != yeastDto.Id)
            {
                return(BadRequest());
            }
            await _yeastService.UpdateAsync(yeastDto);

            return(new StatusCodeResult((int)HttpStatusCode.NoContent));
        }
Esempio n. 8
0
        //private IHopRepository repository = new HopDapperRepository();

        protected override IList <YeastFlavour> ResolveCore(YeastDto dto)
        {
            var flavours = new List <YeastFlavour>();

            foreach (var flavourStr in dto.Flavours)
            {
                flavours.Add(new YeastFlavour {
                    YeastId = dto.Id, Flavour = new Flavour {
                        Name = flavourStr
                    }
                });
            }
            return(flavours);
        }
Esempio n. 9
0
        public async Task <IActionResult> UpdateYeast(YeastViewModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var dto = new YeastDto
            {
                Alcohol   = model.Alcohol,
                Note      = model.Note,
                TempMax   = model.TempMax,
                TempMin   = model.TempMin,
                Trademark = model.Trademark
            };

            if (model.Id.HasValue)
            {
                dto.Id = model.Id.Value;
            }
            if (model.Style != null)
            {
                dto.Style = new Code {
                    Id = model.Style.Id
                }
            }
            ;
            if (model.Brand != null)
            {
                dto.Brand = new Code {
                    Id = model.Brand.Id
                }
            }
            ;

            var cmd = _yeastCommandFactory.CreateYeastsCommand();

            if (dto.Id == 0)
            {
                await cmd.AddAsync(dto).ConfigureAwait(false);
            }
            else
            {
                await cmd.UpdateAsync(dto).ConfigureAwait(false);
            }

            return(RedirectToAction("Index", "Admin", new { id = "yeasts" }));
        }
Esempio n. 10
0
        public YeastViewModel CreateYeastViewModel(YeastDto yeastDto)
        {
            if (yeastDto == null)
            {
                throw new ArgumentNullException(nameof(yeastDto));
            }

            var model = new YeastViewModel
            {
                Id        = yeastDto.Id,
                Brand     = CreateYeastBrandViewModel(yeastDto.Brand),
                Style     = CreateYeastStyleViewModel(yeastDto.Style),
                Trademark = yeastDto.Trademark,
                TempMax   = yeastDto.TempMax,
                TempMin   = yeastDto.TempMin,
                Alcohol   = yeastDto.Alcohol,
                Note      = yeastDto.Note
            };

            model.Brands.AddRange(CreateSelectList("Brand", _yeastBrandsDtoList));
            model.Styles.AddRange(CreateSelectList("Style", _yeastStylesDtoList));

            var dto = new YeastPairDto {
                Yeast = yeastDto.Id
            };

            model.Pairing          = CreateYeastPairingViewModel(dto);
            model.Pairing.Category = null;
            model.Pairing.Variety  = null;

            var pairs = _yeastPairingsDtoList.Where(p => p.Yeast.Value == yeastDto.Id).ToList();

            if (pairs != null)
            {
                model.Pairings.Clear();
                model.Pairings.AddRange(CreateYeastPairingViewModel(pairs));
            }

            return(model);
        }
Esempio n. 11
0
 public static async Task <StyleDto> CreateStyle(FermentableDto fermentable, HopDto hop, YeastDto yeast, string accessToken, HttpClient client)
 {
     var styleToCreate = new Style
     {
         Name       = "American Pale",
         Type       = TestType,
         Thresholds = new List <StyleThreshold> {
             new("abv", 4.0f, 5.5f)
         },
Esempio n. 12
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));
        }
Esempio n. 13
0
        public async Task <IActionResult> Insert([FromBody] YeastDto yeast)
        {
            var yeasts = await _yeastRepository.Add(_mapper.Map <Yeast>(yeast));

            return(Ok(yeasts));
        }