Exemplo n.º 1
0
        public IActionResult Invitation(TerritoryUserInvitation invitation)
        {
            try
            {
                if (!IsUser())
                {
                    return(Forbid());
                }

                if (database.TerritoryUser.Count(u => BasicStrings.StringsEqual(u.Email, invitation.Email)) > 0)
                {
                    return(RedirectToAction(nameof(AlreadyInvited), invitation));
                }

                var now = DateTime.Now;

                var user = new TerritoryUser
                {
                    Id        = Guid.NewGuid(),
                    Email     = invitation.Email,
                    Surname   = invitation.Surname,
                    GivenName = invitation.GivenName,
                    Created   = now,
                    Updated   = now,
                    Role      = "Invited"
                };

                database.TerritoryUser.Add(user);

                if (string.Equals(invitation.AlbaAccount, "this-account"))
                {
                    Guid albaAccountId = albaCredentialService.GetAlbaAccountIdFor(User.Identity.Name);

                    database
                    .TerritoryUserAlbaAccountLink
                    .Add(
                        new TerritoryUserAlbaAccountLink()
                    {
                        TerritoryUserId = user.Id,
                        AlbaAccountId   = albaAccountId,
                        Role            = "Invited",
                        Created         = DateTime.Now,
                        Updated         = DateTime.Now
                    });
                }

                database.SaveChanges();

                return(Ok());
            }
            catch (AlbaCredentialException e)
            {
                return(Redirect($"~/Home/LoginError?message={e.Message}"));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public IActionResult AlreadyInvited(TerritoryUserInvitation invitation)
        {
            try
            {
                if (!IsUser())
                {
                    return(Forbid());
                }

                return(View(invitation));
            }
            catch (Exception e)
            {
                return(NotFound(e.Message));
            }
        }