// AF_Context context = new AF_Context();
  
  #region Award
  public async Task AddAward(Award newAward)
  {
      using (var context = new AF_Context())
      {
          try
          {
              context.Awards.Add(newAward);
              int recordsAffected = await context.SaveChangesAsync();
          }
          catch (Exception ex)
          {
              throw ex;
          }
      }
  }
 public async Task UpdateAward(Award updateData)
 {
     using (var context = new AF_Context())
     {
         try
         {
             /*Award awa = await (from a in context.Awards
                                      where a.AwardId == updateData.AwardId
                                      select a).ToListAsync();*/
             Award awa = context.Awards.First(a => a.AwardId == updateData.AwardId);
             context.Entry(awa).CurrentValues.SetValues(updateData);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task RemoveAward(int id)
 {
     using (var context = new AF_Context())
     {
         try
         {
             /*List<Award> awa = await (from a in context.Awards
                 where a.AwardId == id
                 select a).ToListAsync();*/
             Award awa = context.Awards.First(a => a.AwardId == id);
             context.Awards.Remove(awa);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task AddRelationPersonPlayRole(RelationPersonPlayRole newRelationPersonPlayRole)
 {
     using (var context = new AF_Context())
     {
         try
         {
             context.RelationsPersonPlayRole.Add(newRelationPersonPlayRole);
             int recordsAffected = await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task UpdatePosition(Position updateData)
 {
     using (var context = new AF_Context())
     {
         try
         {
             Position pos = context.Positions.First(p => p.PositionId == updateData.PositionId);
             context.Entry(pos).CurrentValues.SetValues(updateData);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task AddPosition(Position newPosition)
 {
     using (var context = new AF_Context())
     {
         try
         {
             context.Positions.Add(newPosition);
             int recordsAffected = await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task RemovePlay(int id)
 {
     using (var context = new AF_Context())
     {
         try
         {
             Play pla = context.Plays.First(p => p.PlayId == id);
             context.Plays.Remove(pla);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task RemovePerson(int id)
 {
     using (var context = new AF_Context())
     {
         try
         {
             Person per = context.People.First(p => p.PersonId == id);
             context.People.Remove(per);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task AddNews(News newNews)
 {
     using (var context = new AF_Context())
     {
         try
         {
             context.News.Add(newNews);
             int recordsAffected = await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task AddCategory(Category newCategory)
 {
     using (var context = new AF_Context())
     {
         try
         {
             context.Categories.Add(newCategory);
             int recordsAffected = await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task UpdateUser(User updateData)
 {
     using (var context = new AF_Context())
     {
         try
         {
             User us = context.Users.First(u => u.UserId == updateData.UserId);
             context.Entry(us).CurrentValues.SetValues(updateData);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task RemoveUser(int id)
 {
     using (var context = new AF_Context())
     {
         try
         {
             User us = context.Users.First(u => u.UserId == id);
             context.Users.Remove(us);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task AddUser(User newUser)
 {
     using (var context = new AF_Context())
     {
         try
         {
             context.Users.Add(newUser);
             int recordsAffected = await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task UpdateRelationPersonPlayRole(RelationPersonPlayRole updateData)
 {
     using (var context = new AF_Context())
     {
         try
         {
             RelationPersonPlayRole rel = context.RelationsPersonPlayRole.First(r => r.RelationPersonPlayRoleId == updateData.RelationPersonPlayRoleId);
             context.Entry(rel).CurrentValues.SetValues(updateData);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task RemoveRelationPersonPlayRole(int id)
 {
     using (var context = new AF_Context())
     {
         try
         {
             RelationPersonPlayRole rel = context.RelationsPersonPlayRole.First(r => r.RelationPersonPlayRoleId == id);
             context.RelationsPersonPlayRole.Remove(rel);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task RemoveJob(int id)
 {
     using (var context = new AF_Context())
     {
         try
         {
             Job jo = context.Jobs.First(j => j.JobId == id);
             context.Jobs.Remove(jo);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task UpdateJob(Job updateData)
 {
     using (var context = new AF_Context())
     {
         try
         {
             Job jo = context.Jobs.First(j => j.JobId == updateData.JobId);
             context.Entry(jo).CurrentValues.SetValues(updateData);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task RemoveCategory(int id)
 {
     using (var context = new AF_Context())
     {
         try
         {
             Category cat = context.Categories.First(c => c.CategoryId == id);
             context.Categories.Remove(cat);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task RemoveNews(int id)
 {
     using (var context = new AF_Context())
     {
         try
         {
             News ne = context.News.First(n => n.NewsId == id);
             context.News.Remove(ne);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task UpdateCategory(Category updateData)
 {
     using (var context = new AF_Context())
     {
         try
         {
             //TODO: wyczyscic lol
             //Category cat = context.Categories.Find(updateData.CategoryId);
             Category cat = context.Categories.First(c => c.CategoryId==updateData.CategoryId);
             cat.CategoryId = updateData.CategoryId;
             cat.EditDate = updateData.EditDate;
             cat.EditedBy = updateData.EditedBy;
             cat.Group = updateData.Group;
             cat.Order = updateData.Order;
             cat.Title = updateData.Title;
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task UpdateNews(News updateData)
 {
     using (var context = new AF_Context())
     {
         try
         {
             News ne = context.News.First(n => n.NewsId == updateData.NewsId);
             context.Entry(ne).CurrentValues.SetValues(updateData);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task AddFestival(Festival newFestival)
 {
     using (var context = new AF_Context())
     {
         try
         {
             context.Festivals.Add(newFestival);
             int recordsAffected = await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task UpdatePerson(Person updateData)
 {
     using (var context = new AF_Context())
     {
         try
         {
             Person per = context.People.First(a => a.PersonId == updateData.PersonId);
             context.Entry(per).CurrentValues.SetValues(updateData);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task RemoveFestival(int id)
 {
     using (var context = new AF_Context())
     {
         try
         {
             Festival fes = context.Festivals.First(f => f.FestivalId == id);
             context.Festivals.Remove(fes);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task UpdatePlay(Play updateData)
 {
     using (var context = new AF_Context())
     {
         try
         {
             Play pla = context.Plays.First(p => p.PlayId == updateData.PlayId);
             context.Entry(pla).CurrentValues.SetValues(updateData);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task UpdateFestival(Festival updateData)
 {
     using (var context = new AF_Context())
     {
         try
         {
             Festival fes = context.Festivals.First(f => f.FestivalId == updateData.FestivalId);
             context.Entry(fes).CurrentValues.SetValues(updateData);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task RemovePosition(int id)
 {
     using (var context = new AF_Context())
     {
         try
         {
             Position pos = context.Positions.First(p => p.PositionId == id);
             context.Positions.Remove(pos);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task AddJob(Job newJob)
 {
     using (var context = new AF_Context())
     {
         try
         {
             context.Jobs.Add(newJob);
             int recordsAffected = await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task AddRelationFestivalPersonPosition(RelationFestivalPersonPosition newRelationFestivalPersonPosition)
 {
     using (var context = new AF_Context())
     {
         try
         {
             context.RelationsFestivalPersonPosition.Add(newRelationFestivalPersonPosition);
             int recordsAffected = await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
 public async Task RemoveRelationFestivalPersonPosition(int id)
 {
     using (var context = new AF_Context())
     {
         try
         {
             RelationFestivalPersonPosition rel = context.RelationsFestivalPersonPosition.First(r => r.RelationFestivalPersonPositionId == id);
             context.RelationsFestivalPersonPosition.Remove(rel);
             await context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }