Exemplo n.º 1
0
        public async Task <IActionResult> Update([FromBody] CookDto cookDto)
        {
            var cookId = JwtMetaData.CookId;

            async Task <CookDto> UpdateCook()
            {
                cookDto.Id = cookId;

                await _cookValidator.ValidateEntityAsync(cookDto, RuleSets.Cooks.ToString());

                var cook = _mapper.Map <Cook>(cookDto);

                await _locationHelper.SetPostcodeLocation(cook.Address, cookDto.Id);

                var savedCook = _mapper.Map <CookDto>(await _cookRepo.Save(cook));

                if (savedCook != null)
                {
                    var foodBusReg = await _foodBusRepo.GetByCookId(cookId);

                    savedCook.FoodBusinessRegistrationId = foodBusReg?.Id;
                }

                return(savedCook);
            }

            return(await Execute(UpdateCook));
        }
        private async Task <string> GetCooksFoodBusinessRegistrationId(string cookId)
        {
            var foodBusReg = await _foodBusRegRepo.GetByCookId(cookId);

            return(foodBusReg?.Id);
        }