public async Task <IActionResult> Activate(string email, int userId)
        {
            var invitations = await db.CompanyInvitations
                              .Where(x => x.Email == email && x.Status == InvitationStatus.Accepted)
                              .ToArrayAsync();

            var madeAnActivation = false;

            foreach (var invitation in invitations)
            {
                var companyUser = new CompanyUser
                {
                    CompanyId  = invitation.CompanyId,
                    UserId     = userId,
                    IsFavorite = true
                };
                db.Add(companyUser);
                db.Remove(invitation);

                await db.SaveChangesAsync();

                madeAnActivation = true;
            }

            return(Ok(madeAnActivation));
        }
Exemple #2
0
        public async Task <IActionResult> Delete(int companyId, int userId)
        {
            var user = await db.CompanyUsers.SingleOrDefaultAsync(x => x.CompanyId == companyId && x.UserId == userId);

            db.Remove(user);
            await db.SaveChangesAsync();

            return(NoContent());
        }