public async Task <IActionResult> CreateBilledstyringAsync([FromBody] Models.Billedstyring Billedstyring) { var newproduct = await billedstyringService.PostBilledstyringAsync(Billedstyring); if (newproduct.IsSuccess) { return(Ok(newproduct.Billedstyring)); } return(NotFound(newproduct.ErrorMessage)); }
public async Task <(bool IsSuccess, Db.Billedstyring Billedstyring, string ErrorMessage)> PostBilledstyringAsync([FromBody] Models.Billedstyring Billedstyring) { try { logger?.LogInformation("Creating products"); var mapper = configurationProvider.CreateMapper(); var newproduct = mapper.Map <Db.Billedstyring>(Billedstyring); if (newproduct != null) { await dbContext.Billedstyring.AddAsync(newproduct); await dbContext.SaveChangesAsync(); logger?.LogInformation($"product created {newproduct}"); var createPostCustomerCommand = new CreatePostBilledstyringCommand(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); } }