public async Task <IActionResult> AddInvitation(AddInvitation invitation) { if (await _service.AddInvitation(invitation)) { return(Ok(new { status = "OK", message = "Poprawnie wysłano zaproszenie!" })); } return(Ok(new { status = "Exists", message = "Wysłałeś już takie zaproszenie!" })); }
public Invitation(AddInvitation invitation) { EventId = invitation.EventId; SenderId = invitation.UserIdSender; RecipientId = invitation.UserIdRept; IsNew = true; IsAccepted = false; Type = invitation.InvitationType; }
private async Task <bool> ChechIsExists(AddInvitation addInvitation) { int isExists = await _context.Invitations.CountAsync(x => (x.SenderId == addInvitation.UserIdSender) && (x.RecipientId == addInvitation.UserIdRept) && (addInvitation.EventId == x.EventId)); if (isExists == 0) { return(false); } return(true); }
public async Task <bool> AddInvitation(AddInvitation invitation) { Invitation dbInvi = new Invitation(invitation); if (!await ChechIsExists(invitation)) { _context.Invitations.Add(dbInvi); await _context.SaveChangesAsync(); return(true); } return(false); }