Added accept and decline functions
This commit is contained in:
parent
5f8054f88f
commit
854652d7ab
Binary file not shown.
Binary file not shown.
@ -47,8 +47,33 @@ namespace StudyLib.API.Controllers
|
|||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpDelete("delete/{groupId}/{userId}")]
|
[HttpGet("accept/{groupId}/{userId}")]
|
||||||
public async Task<IActionResult> DeleteGroupCandidate(long groupId, string 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();
|
var groupCandidate = await _context.GroupCandidates.Where(g => g.Group.ID == groupId && g.User.Id == userId).FirstAsync();
|
||||||
if (groupCandidate == null)
|
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.
Binary file not shown.
Loading…
Reference in New Issue
Block a user