public async Task <Locale> UpdateLocale(int localeId, CreateOrUpdateLocaleCommand command) { var locale = await this.FindLocaleById(localeId, null); locale.Name = command.Name ?? locale.Name; locale.Description = command.Description ?? locale.Description; locale.Latitude = command.Latitude ?? locale.Latitude; locale.Longitude = command.Longitude ?? locale.Longitude; await this.databaseContext.SaveChangesAsync(); return(locale); }
public async Task <Locale> CreateLocale(CreateOrUpdateLocaleCommand command) { if (string.IsNullOrEmpty(command.Name)) { throw new InvalidParametersException("Name", command.Name, "Name can't be null or empty"); } if (!command.Latitude.HasValue) { throw new InvalidParametersException("Latitude", command.Latitude, "Latitude can't be null"); } if (!command.Longitude.HasValue) { throw new InvalidParametersException("Longitude", command.Longitude, "Longitude can't be null"); } var locale = new Locale(command.Name, command.Description, command.Latitude.Value, command.Longitude.Value); this.databaseContext.Add(locale); await this.databaseContext.SaveChangesAsync(); return(locale); }