示例#1
0
        public async Task <IActionResult> CreateProductAsync([FromBody] Models.Varelagerstyring product)
        {
            var newproduct = await varelagerstyringService.PostVarelagerstyringAsync(product);

            if (newproduct.IsSuccess)
            {
                return(Ok(newproduct.Varelagerstyring));
            }
            return(NotFound(newproduct.ErrorMessage));
        }
        public async Task <(bool IsSuccess, Db.Varelagerstyring Varelagerstyring, string ErrorMessage)> PostVarelagerstyringAsync(Models.Varelagerstyring Varelagerstyring)
        {
            try
            {
                logger?.LogInformation("Creating products");
                var mapper     = configurationProvider.CreateMapper();
                var newproduct = mapper.Map <Db.Varelagerstyring>(Varelagerstyring);
                if (newproduct != null)
                {
                    await dbContext.Varelagerstyring.AddAsync(newproduct);

                    await dbContext.SaveChangesAsync();

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

                    var createPostCustomerCommand = new CreatePostVarelagerstyringCommand(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);
            }
        }