public IActionResult EditName(string recordLabelName, int recordLabelId)
        {
            var model       = new MyAccountViewModel();
            var recordLabel = _recordLabelManager.GetOne(x => x.Id == recordLabelId, includeProperties: $"{ nameof(RecordLabel.User)}");


            if (string.IsNullOrWhiteSpace(recordLabelName))
            {
                ModelState.AddModelError("Name", "The Name must contain at least 2 characters");
                return(View("MyAccount", model));
            }
            recordLabelName = recordLabelName.Trim();
            if (recordLabelName.Length < 2)
            {
                ModelState.AddModelError("Name", "The Name must contain at least 2 characters");
                return(View("MyAccount", model));
            }
            if (recordLabelName.Length > 50)
            {
                ModelState.AddModelError("Name", "The Name cannot contain more than 50 characters");
                return(View("MyAccount", model));
            }

            recordLabel.User.Name = recordLabelName;
            _recordLabelManager.Update(recordLabel, recordLabel.Id);
            _recordLabelManager.Save();

            return(RedirectToAction("MyAccount"));
        }
Example #2
0
        public IActionResult AddNewRecordLabel(InviteViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var response = _userManager.CreateUser(model.Name, model.Email, Role.RecordLabel);

            if (response == null)
            {
                ModelState.AddModelError("Email", "Email already exists");
                return(View(model));
            }
            var user = response.Result;

            _recordLabelManager.Create(new RecordLabel()
            {
                User = user
            }, CurrentLoggedUserId);
            _recordLabelManager.Save();
            var code        = _userManager.GeneratePasswordResetTokenAsync(user).Result;
            var callbackUrl = Url.ResetPasswordCallbackLink(user.Id.ToString(), code, Request.Scheme);

            _emailsManager.PrepareSendMail(EmailTemplateType.InvitedRecordLabel, model.Email, callbackUrl);

            return(View("SuccessfullyInvited"));
        }