Esempio n. 1
0
        public async Task <IActionResult> SendInvitation([FromBody] Invitation invitation)
        {
            var companyId = this.User.Claims.SingleOrDefault(c => c.Type == "companyId").Value;

            if (await invitationProvider.CheckIfEmailIsInvited(invitation.Email))
            {
                return(BadRequest("Has already been invited"));
            }
            invitation.SentOn    = DateTime.Now;
            invitation.CompanyId = companyId;
            var isEmailSent = await emailProvider.SendInvitationEmail(invitation);

            if (!isEmailSent)
            {
                return(BadRequest("Email wasn't sent"));
            }
            var dbInvitation = await invitationProvider.AddInvitation(invitation);

            return(Ok(dbInvitation));
        }