public async Task <Position> UpdatePosition(int positionId, CreateOrUpdatePositionCommand command) { var position = await this.FindPositionById(positionId); position.ZoneId = command.ZoneId ?? position.ZoneId; position.Name = command.Name ?? position.Name; position.X = command.X ?? position.X; position.Y = command.X ?? position.Y; position.Z = command.X ?? position.Z; await this.databaseContext.SaveChangesAsync(); return(position); }
public async Task <Position> CreatePosition(CreateOrUpdatePositionCommand command) { var zone = await this.databaseContext.Zones.FindAsync(command.ZoneId); if (zone == null) { throw new InvalidParametersException("ZoneId", command.ZoneId, "An existing zoneId must be provided for position"); } if (string.IsNullOrEmpty(command.Name)) { throw new InvalidParametersException("Name", command.Name, "A name must be provided for position"); } var position = new Position(command.ZoneId !.Value, command.Name, command.X ?? 0, command.Y ?? 0, command.Z ?? 0); this.databaseContext.Add(position); await this.databaseContext.SaveChangesAsync(); return(position); }