Example #1
0
 /// <summary>
 /// Get all football players
 /// </summary>
 /// <param name="dbContext"></param>
 /// <returns></returns>
 public async Task<List<Event>> GetAsync(DbContext dbContext)
 {
   var collection = dbContext.database.GetCollection<Event>(typeof(Event).Name);
   var filter = Builders<Event>.Filter.Empty;
   var events = await collection.FindAsync(filter).ConfigureAwait(false);
   return await events.ToListAsync();
 }
Example #2
0
 /// <summary>
 /// Updates a property of an event
 /// </summary>
 /// <param name="context"></param>
 public async Task UpdateAsync(DbContext dbContext, string id, string property, object newValue)
 {
   var teamEvent = dbContext.database.GetCollection<Event>("Event");
   var filter = Builders<Event>.Filter.Eq("_id", ObjectId.Parse(id));
   var update = Builders<Event>.Update.Set(property, newValue);
   await teamEvent.UpdateOneAsync(filter, update).ConfigureAwait(false);
 }
Example #3
0
 /// <summary>
 /// Get event by id
 /// </summary>
 /// <param name="dbContext"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public async Task<Event> GetAsync(DbContext dbContext, string id)
 {
   var collection = dbContext.database.GetCollection<Event>(typeof(Event).Name);
   var filter = Builders<Event>.Filter.Eq("_id", ObjectId.Parse(id));
   var player = await collection.FindAsync(filter).ConfigureAwait(false);
   return await player.FirstOrDefaultAsync();
 }
    public async Task<IEnumerable<FootballPlayer>> GetAsync()
    {
      try
      {
        var dbContext = new DbContext();
        var playersRepository = new FootballPlayersRepository();

        return await playersRepository.GetAsync(dbContext);
      }
      catch (Exception ex)
      {
        _logger.LogError("Error occured: {0}", ex);
        return null;
      }
    }
Example #5
0
    /// <summary>
    /// Removes an event from db
    /// </summary>
    /// <param name="dbContext"></param>
    /// <param name="id"></param>
    /// <returns></returns>
    public async Task<bool> RemoveAsync(DbContext dbContext, string id)
    {
      var filter = Builders<Event>.Filter.Eq("_id", ObjectId.Parse(id));
      var collection = dbContext.database.GetCollection<Event>(typeof(Event).Name);
      var myevent = await collection.DeleteOneAsync(filter).ConfigureAwait(false);

      if (myevent.DeletedCount == 1)
      {
        return true;
      }
      else
      {
        return false;
      }
    }
Example #6
0
    public async Task<IEnumerable<Event>> GetAsync()
    {
      try
      {
        var dbContext = new DbContext();
        var eventsRepository = new EventsRepository();

        return await eventsRepository.GetAsync(dbContext);
      }
      catch (Exception ex)
      {
        _logger.LogError("Error occured: {0}", ex);
        return null;
      }
    }
    public async Task<Dictionary<string, int>> GetFootballplayersAssignment()
    {
      try
      {
        var dbContext = new DbContext();
        var playersService = new FootballPlayersService();

        var result = await playersService.PositionAssignmentAsync(dbContext);

        return result;
      }
      catch (Exception ex)
      {
        _logger.LogError("Error occured: {0}", ex);
        return null;
      }
    }
Example #8
0
    public async Task PostAsync([FromBody]dynamic data)
    {
      try
      {
        var newEvent = new Event();
        newEvent.Name = data["Name"].ToString();
        newEvent.StartTime = data["StartTime"];
        newEvent.Type = data["Type"];

        var dbContext = new DbContext();
        await newEvent.InsertAsync(dbContext);
      }
      catch (Exception ex)
      {
        _logger.LogError("Error occured: {0}", ex);
      }

    }
Example #9
0
    public async Task Put(string id, [FromBody]dynamic data)
    {
      try
      {
        var dbContext = new DbContext();
        var eventsRepository = new EventsRepository();

        var myEvent = await eventsRepository.GetAsync(dbContext, id);

        JValue newName = (JValue)data["Name"];


        if (!string.IsNullOrEmpty(newName?.ToString()))
        {
          await eventsRepository.UpdateAsync(dbContext, id, "Name", newName.ToString());
        }

        JValue newType = (JValue)data["Type"];
        int typeResult = 0;

        if (int.TryParse(newType?.ToString(), out typeResult))
        {
          await eventsRepository.UpdateAsync(dbContext, id, "Type", typeResult.ToString());
        }

        JValue newStartTime = (JValue)data["startsAt"];
        DateTime newTime;

        if (DateTime.TryParse(newStartTime?.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'"), out newTime))
        {
          await eventsRepository.UpdateAsync(dbContext, id, "StartTime", newTime);
        }

      }
      catch (Exception ex)
      {
        _logger.LogError("Error occured: {0}", ex);
      }
    }
    public async Task<int> GetCountPlayersAsync([FromQuery] bool active)
    {
      try
      {
        var dbContext = new DbContext();
        var playersRepository = new FootballPlayersRepository();

        if (active)
        {
          return await playersRepository.GetCountActiveAsync(dbContext);
        }
        else
        {
          return await playersRepository.GetCountAsync(dbContext);
        }

      }
      catch (Exception ex)
      {
        _logger.LogError("Error occured: {0}", ex);
        return 0;
      }

    }
    public async Task PostAsync([FromBody]dynamic data)
    {
      try
      {
        JValue firstname = (JValue)data["Firstname"];
        JValue lastname = (JValue)data["Lastname"];

        var newPlayer = new FootballPlayer();
        newPlayer.Firstname = firstname.ToString();
        newPlayer.Lastname = lastname.ToString();

        var dbContext = new DbContext();
        await newPlayer.SaveAsync(dbContext);
      }
      catch (Exception ex)
      {
        _logger.LogError("Error occured: {0}", ex);
      }
    }
    public async Task<IActionResult> UpdatePeriodsAsync(string id, [FromBody]dynamic data)
    {
      try
      {
        var dbContext = new DbContext();
        var playersRepository = new FootballPlayersRepository();

        var player = await playersRepository.GetAsync(dbContext, id);

        if (player == null)
        {
          return HttpNotFound();
        }
        else
        {
          var array = ((JObject)data)["periods"];

          List<PositionTimeperiod> list = new List<PositionTimeperiod>();

          foreach (var item in array)
          {
            var positionPeriod = item.ToObject<PositionTimeperiod>();
            list.Add(positionPeriod);
          }

          var updateResult = await playersRepository.Update(dbContext, id, list);

          if (updateResult.IsModifiedCountAvailable && updateResult.ModifiedCount == 1)
          {
            return Ok();
          }

          return HttpBadRequest();
        }
      }
      catch (Exception ex)
      {
        _logger.LogError("Error occured: {0}", ex);
        return HttpBadRequest();
      }

    }
    public async Task<IActionResult> UpdateAsync(string id)
    {
      try
      {
        string Column = Request.Headers["Column"];
        string NewValue = Request.Headers["NewValue"];

        if (Column == string.Empty || NewValue == string.Empty)
        {
          return HttpBadRequest();
        }

        var dbContext = new DbContext();
        var playersRepository = new FootballPlayersRepository();

        var updateResult = await playersRepository.Update(dbContext, id, Column, NewValue);

        if (updateResult.IsModifiedCountAvailable && updateResult.ModifiedCount == 1)
        {
          return Ok();
        }
        else
        {
          return HttpNotFound();
        }

      }
      catch (Exception ex)
      {
        _logger.LogError("Error occured: {0}", ex);
        return HttpBadRequest();
      }

    }
Example #14
0
 /// <summary>
 /// Speichert eine Zeitreihe in die Datenbank
 /// </summary>
 /// <param name="context"></param>
 public async Task SaveAsync(DbContext dbContext)
 {
   var player = dbContext.database.GetCollection<FootballPlayer>("FootballPlayer");
   await player.InsertOneAsync(this).ConfigureAwait(false);
 }
Example #15
0
    public async Task<bool> DeleteAsync(string id)
    {
      try
      {
        var dbContext = new DbContext();
        var eventsRepository = new EventsRepository();

        return await eventsRepository.RemoveAsync(dbContext, id);
      }
      catch (Exception ex)
      {
        _logger.LogError("Error occured: {0}", ex);
        return false;
      }
    }
Example #16
0
 /// <summary>
 /// Speichert eine Zeitreihe in die Datenbank
 /// </summary>
 /// <param name="context"></param>
 public async Task InsertAsync(DbContext dbContext)
 {
   var teamEvent = dbContext.database.GetCollection<Event>("Event");
   await teamEvent.InsertOneAsync(this).ConfigureAwait(false);
 }