public async Task <IActionResult> ActivateWithInactiveOrganization([FromBody] UserApprovalModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userIdVal = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (string.IsNullOrEmpty(userIdVal))
            {
                return(BadRequest("Invalid attempt"));
            }

            int approvedById = Convert.ToInt32(userIdVal);

            model.ApprovedById = approvedById;
            string loginUrl = HttpContext.RequestServices.GetRequiredService <IConfiguration>()
                              .GetValue <String>("LoginUrl");
            var response = await userService.ActivateWithInactiveOrganization(model, loginUrl, defaultUserEmail);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }
            return(Ok(response.Success));
        }
        public IActionResult ActivateAccount([FromBody] UserApprovalModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userIdVal = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (string.IsNullOrEmpty(userIdVal))
            {
                return(BadRequest("Invalid attempt"));
            }

            int approvedById = Convert.ToInt32(userIdVal);

            model.ApprovedById = approvedById;
            var response = userService.ActivateUserAccount(model);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }
            return(Ok(response.Success));
        }
Beispiel #3
0
        public ActionResponse ActivateUserAccount(UserApprovalModel model)
        {
            using (var unitWork = new UnitOfWork(context))
            {
                ActionResponse response = new ActionResponse();
                IMessageHelper mHelper;
                EFUser         userAccount       = null;
                EFUser         approvedByAccount = null;

                var userAccounts = unitWork.UserRepository.GetMany(u => u.Id.Equals(model.ApprovedById) || u.Id.Equals(model.UserId));
                foreach (var user in userAccounts)
                {
                    if (user.Id.Equals(model.ApprovedById))
                    {
                        approvedByAccount = user;
                    }
                    else if (user.Id.Equals(model.UserId))
                    {
                        userAccount = user;
                    }
                }
                if (approvedByAccount == null)
                {
                    mHelper          = new MessageHelper();
                    response.Message = mHelper.GetNotFound("Approved By");
                    response.Success = false;
                    return(response);
                }
                if (userAccount == null)
                {
                    mHelper          = new MessageHelper();
                    response.Message = mHelper.GetNotFound("User");
                    response.Success = false;
                    return(response);
                }

                var notification = unitWork.NotificationsRepository.GetByID(model.NotificationId);
                if (notification == null)
                {
                    mHelper          = new MessageHelper();
                    response.Success = false;
                    response.Message = mHelper.GetNotFound("Notification");
                    return(response);
                }

                userAccount.IsApproved = true;
                userAccount.ApprovedBy = approvedByAccount;
                userAccount.ApprovedOn = DateTime.Now;

                unitWork.UserRepository.Update(userAccount);
                unitWork.NotificationsRepository.Delete(notification);

                unitWork.Save();
                response.ReturnedId = userAccount.Id;
                return(response);
            }
        }
        public IActionResult Activate([FromBody] UserApprovalModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var response = userService.ActivateUserAccount(model);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }
            SuccessModel successModel = new SuccessModel()
            {
                Message = response.ReturnedId.ToString()
            };

            return(Ok(successModel));
        }
        public async Task <IActionResult> Activate([FromBody] UserApprovalModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            string loginUrl = HttpContext.RequestServices.GetRequiredService <IConfiguration>()
                              .GetValue <String>("LoginUrl");
            var response = await userService.ActivateUserAccountAsync(model, loginUrl, defaultUserEmail);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }
            SuccessModel successModel = new SuccessModel()
            {
                Message = response.ReturnedId.ToString()
            };

            return(Ok(successModel));
        }