Example #1
0
        public IActionResult AddAccessToAccount(AddAccessViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectWithError(ExpenseManagerResource.InvalidInputData));
            }

            var user = GetUserFromEmail(model.Email);

            if (user == null)
            {
                return(RedirectWithError(ExpenseManagerResource.EmailDoesntExist));
            }
            if (user.AccountId != Guid.Empty) // todo this might not be best check
            {
                return(RedirectWithError(ExpenseManagerResource.AlreadyHasAccount));
            }

            var account = CurrentAccountProvider.GetCurrentAccount(HttpContext.User);

            _accountFacade.AttachAccountToUser(user.Id, account.Id, model.AccessType);

            return(RedirectToAction("Index", new { successMessage = ExpenseManagerResource.AccessGranted }));
        }