public async Task <Zone> UpdateZone(int zoneId, CreateOrUpdateZoneCommand command) { var zone = await this.FindZoneById(zoneId); zone.LocaleId = command.LocaleId ?? zone.LocaleId; zone.Name = command.Name ?? zone.Name; zone.Description = command.Description ?? zone.Description; zone.Floor = command.Floor ?? zone.Floor; await this.databaseContext.SaveChangesAsync(); return(zone); }
public async Task <Zone> CreateZone(CreateOrUpdateZoneCommand command) { var locale = await this.databaseContext.Locales.FindAsync(command.LocaleId); if (locale == null) { throw new InvalidParametersException("LocaleId", command.LocaleId, "An existing localeId must be provided for zone"); } if (string.IsNullOrEmpty(command.Name)) { throw new InvalidParametersException("Name", command.Name, "A name must be provided for zone"); } var zone = new Zone(command.LocaleId !.Value, command.Name, command.Description, command.Floor ?? 0); this.databaseContext.Add(zone); await this.databaseContext.SaveChangesAsync(); return(zone); }