public CitySavedResult CreateCity(CityModel cityModel) { var cityName = ProcessCityName(cityModel.Name); // TODO: use any mapper (AutoMapper, Mapster) var city = new City { Name = cityName, FoundationDate = cityModel.FoundationDate, ScreenLayout = cityModel.ScreenLayout != null ? new ScreenLayout { PercentageX = cityModel.ScreenLayout.PercentageX, PercentageY = cityModel.ScreenLayout.PercentageY } : null }; // TODO: try to encapsulate exceptions handling logic for all repo.Save actions for all use cases try { _citiesRepository.Create(city); _citiesRepository.Save(); _messageProducer.ProduceCityCreated(new CityCreatedMessage { SolutionOneCityId = city.Id, Name = city.Name, FoundationDate = city.FoundationDate }); return(_postResultFactory.Success <CitySavedResult>(additionalSetup: x => x.CityId = city.Id)); } // TODO: catch custom DbSave exception catch (Exception e) { return(_postResultFactory.Error <CitySavedResult>("Unexpected error", e)); } }