public async Task <IActionResult> Register(MerchantRegisterInput input) { var existingMerchant = await Mongo.GetMerchantByFiscalCode(input.FiscalCode); if (existingMerchant != null) { return(this.ProblemParameter("Supplied fiscal code is already registered")); } if (!User.GetUserId(out var loggedUserId)) { return(Forbid()); } try { var merchant = new Merchant { Name = input.Name, FiscalCode = input.FiscalCode, PrimaryActivityType = input.PrimaryActivity, Address = input.Address, ZipCode = input.ZipCode, City = input.City, Country = input.Country, Description = input.Description, WebsiteUrl = input.Url, CreatedOn = DateTime.UtcNow, AdministratorIds = new ObjectId[] { loggedUserId } }; await Mongo.CreateMerchant(merchant); return(CreatedAtAction( nameof(GetInformation), new { id = merchant.Id }, merchant.ToOutput() )); } catch (Exception ex) { Logger.LogError(ex, "Failed to register new merchant with fiscal code {0}", input.FiscalCode); throw; } }