public async Task <IActionResult> CreateKundestyringAsync([FromBody] Models.Kundestyring Kundestyring)
        {
            var newproduct = await kundestyringService.PostKundestyringAsync(Kundestyring);

            if (newproduct.IsSuccess)
            {
                return(Ok(newproduct.Kundestyring));
            }
            return(NotFound(newproduct.ErrorMessage));
        }
예제 #2
0
        public async Task <(bool IsSuccess, Db.Kundestyring Kundestyring, string ErrorMessage)> PostKundestyringAsync([FromBody] Models.Kundestyring Kundestyring)
        {
            try
            {
                logger?.LogInformation("Creating products");
                var mapper     = configurationProvider.CreateMapper();
                var newproduct = mapper.Map <Db.Kundestyring>(Kundestyring);
                if (newproduct != null)
                {
                    await dbContext.Kundestyring.AddAsync(newproduct);

                    await dbContext.SaveChangesAsync();

                    logger?.LogInformation($"Kundestyring created {newproduct}");

                    var createPostCustomerCommand = new CreatePostKundestyringCommand(newproduct.Id, newproduct.Name, newproduct.Categories);
                    await _eventBus.SendCommand(createPostCustomerCommand);


                    return(true, newproduct, null);
                }
                return(false, null, "Not created");
            }
            catch (Exception ex)
            {
                logger?.LogError(ex.ToString());
                return(false, null, ex.Message);
            }
        }