internal async Task <ResultObject> HandleAsync(CreateEventCommand command) { if (!await _cloudTable.ExistsAsync()) { await _cloudTable.CreateAsync(); } // Validation logic goes here... var model = CreateEventModel(command); var operation = TableOperation.Insert(model); try { var tableResult = await _cloudTable.ExecuteAsync(operation); if (tableResult.HttpStatusCode == 204 && tableResult.Result is EventModel eventModel) { return new ResultObject { Success = true, Result = eventModel.RowKey, Message = string.Empty } } ; else { return new ResultObject { Success = false, Result = null, Message = "Unable to create entity" } }; } catch (StorageException) { throw; } }
// TODO : This entity should be DTO. private EventModel CreateEventModel(CreateEventCommand command) { return(new EventModel { PartitionKey = command.Client.ToString(), RowKey = Guid.NewGuid().ToString(), Title = command.Title, Description = command.Description, Address = command.Address, Place = command.Place, Country = command.Country }); }