Пример #1
0
 public ActionResult EditUser(Consumer consumer)
 {
     if (consumer.Id == Guid.Parse("00000000-0000-0000-0000-000000000000"))
     {
         consumer.Id = UserStore.CreateUser(User.Identity.Name);
     }
     ConsumerBroker.Save(consumer);
     return(RedirectToAction("Overview", "Consumer", new { id = 5 }));
 }
        public async Task <ActionResult> CreateAsync(CreateUserViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var newUser = UserStore.CreateUser();
                newUser.CompanyId = CompanyId;
                newUser.UserName  = vm.UserName;
                newUser.Email     = vm.Email;

                try
                {
                    var created = await userManager.CreateAsync(newUser, GenerateTempPassword(7));

                    if (created.Succeeded)
                    {
                        await userManager.AddToRoleAsync(newUser.Id, "User");

                        // Send confirmation email.
                        var code = await userManager.GenerateEmailConfirmationTokenAsync(newUser.Id);

                        var url = Url.Action("ActivateAccount", "Security", new { area = "", userId = newUser.Id, code = code }, protocol: Request.Url.Scheme);
                        using (var emailClient = new EmailClient())
                        {
                            await emailClient.SendEmail("Confirm PM Account", "<p>Please confirm your account by clicking this link: <a href=\"" + url + "\">link</a></p>", newUser.Email);
                        }

                        // TODO: PUT THIS IN THE BASE CONTROLLER.
                        var users = await UserStore.GetUsersByCompanyIdAsync(CompanyId, this.ToNavPropertyString(nameof(IUserPoco.UserRoles), nameof(IUserRolePoco.Role)));

                        var usersVm = Mapper.Map <IEnumerable <UserPreviewViewModel> >(users);

                        Response.StatusCode = (int)HttpStatusCode.OK;
                        return(Json(new { success = true, responseText = "User is created successfuly.", html = this.RenderView("_UsersList", usersVm) }, JsonRequestBehavior.AllowGet));
                    }
                }
                catch (Exception ex)
                {
                    SetErrorResponse(HttpStatusCode.InternalServerError, "Something went wrong");
                }
            }

            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(PartialView("_NewUserModal", vm));
        }
Пример #3
0
 public bool CreateUser(UserCreateViewModel model, string userCreate)
 {
     try
     {
         var userStore = new UserStore();
         var dt        = userStore.CreateUser(model, userCreate);
         if (dt)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public IActionResult CreateUser(User user)
 {
     us.CreateUser(user);
     return(Created(user.Email, user));
 }
Пример #5
0
 public void CreateUser(string userName)
 {
     userStore.CreateUser(userName);
 }