public virtual IActionResult Create(ResearcherModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageResearchers))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var researcher = model.ToEntity <Researcher>();

                if (model.ParseDateOfBirth() != null)
                {
                    researcher.Birthdate = model.ParseDateOfBirth();
                }
                researcher.IsActive = true;
                _researcherService.InsertResearcher(researcher);

                var address = model.AddressModel.ToEntity <Address>();
                SaveAddress(model.AddressModel, address);
                if (address.Id != 0)
                {
                    researcher.AddressId = address.Id;
                    _researcherService.UpdateResearcher(researcher);
                }


                SuccessNotification("Admin.ContentManagement.Researchers.Added");

                //activity log
                //_userActivityService.InsertActivity("AddNewResearcher", "ActivityLog.AddNewResearcher", researcher);

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                //selected tab
                SaveSelectedTabName();

                return(RedirectToAction("Edit", new { id = researcher.Id }));
            }

            //prepare model
            model = _researcherModelFactory.PrepareResearcherModel(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 2
0
        public virtual IActionResult AccountActivation(string token, string email)
        {
            var user = _userService.GetUserByEmail(email);

            if (user == null)
            {
                return(RedirectToAction("Login", "User"));
            }

            var userAccountActivationAttribute = _genericAttributeService.GetAttributesForEntityByToken(user.Id, nameof(user), ResearchUserDefaults.AccountActivationTokenAttribute)
                                                 .Where(x => x.Value.Contains(token)).FirstOrDefault();
            string cToken     = userAccountActivationAttribute != null ? userAccountActivationAttribute.Value : string.Empty;
            var    researcher = _researcherService.GetResearcherByEmail(email);

            if (researcher.IsCompleted)
            {
                return
                    (View(new AccountActivationModel
                {
                    Result = "ระบบยืนยันอีเมลของเท่านเรียบร้อยแล้ว โปรดล็อคอินเข้าสู่ระบบ !"
                }));
            }

            //if (!cToken.Equals(token, StringComparison.InvariantCultureIgnoreCase))
            if (string.IsNullOrEmpty(cToken))
            {
                return(RedirectToAction("Login", "User"));
            }

            //activate researcher account
            researcher.IsCompleted = true;
            researcher.Modified    = DateTime.UtcNow;
            _researcherService.UpdateResearcher(researcher);
            user.Modified = DateTime.UtcNow;
            _userService.UpdateUser(user);
            _genericAttributeService.SaveAttribute(user, ResearchUserDefaults.AccountActivationTokenAttribute, "");

            //send welcome message
            _workflowMessageService.SendUserWelcomeMessage(user, 0);

            var model = new AccountActivationModel
            {
                Result = "ยินดีต้อนรับเข้าสู่ระบบสารสนเทศเพื่อการบริหารงานวิจัย ระบบได้ยืนยันอีเมลของเท่าน โปรดล็อคอินเข้าสู่ระบบ !"
            };

            return(View(model));
        }