Added accept and decline functions

This commit is contained in:
JakubWalkowiak 2021-01-03 14:22:26 +01:00
parent 5f8054f88f
commit 854652d7ab
10 changed files with 27 additions and 2 deletions

Binary file not shown.

View File

@ -47,8 +47,33 @@ namespace StudyLib.API.Controllers
return NoContent();
}
[HttpDelete("delete/{groupId}/{userId}")]
public async Task<IActionResult> DeleteGroupCandidate(long groupId, string userId)
[HttpGet("accept/{groupId}/{userId}")]
public async Task<IActionResult> AcceptGroupCandidate(long groupId, string userId)
{
var groupCandidate = await _context.GroupCandidates.Where(g => g.Group.ID == groupId && g.User.Id == userId).FirstAsync();
if (groupCandidate == null)
{
return NotFound();
}
_context.GroupCandidates.Remove(groupCandidate);
var user = await _context.Users.FindAsync(userId);
var group = await _context.Groups.Where(g => g.ID == groupId).Include(g => g.Users).FirstAsync();
if (!group.Users.Contains(user))
{
group.Users.Add(user);
_context.Entry(group).State = EntityState.Modified;
}
await _context.SaveChangesAsync();
return NoContent();
}
[HttpDelete("decline/{groupId}/{userId}")]
public async Task<IActionResult> DeclineGroupCandidate(long groupId, string userId)
{
var groupCandidate = await _context.GroupCandidates.Where(g => g.Group.ID == groupId && g.User.Id == userId).FirstAsync();
if (groupCandidate == null)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.