Ejemplo n.º 1
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;
      }
    }
Ejemplo n.º 2
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);
      }
    }
Ejemplo n.º 3
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;
      }
    }