Exemplo n.º 1
0
        public async Task <ActionResult> SaveUser(UserViewModel model)
        {
            using (UserServiceClient client = new UserServiceClient())
            {
                User u = new User()
                {
                    UserName    = model.UserName,
                    Description = model.Description,
                    Editor      = User.Identity.Name,
                    EditTime    = DateTime.Now,
                    IsActive    = model.IsActive,
                    IsApproved  = model.IsApproved,
                    IsLocked    = model.IsLocked,
                    Email       = model.Email,
                    MobilePhone = model.MobilePhone,
                    OfficePhone = model.OfficePhone,
                    Password    = model.Password,
                    CreateTime  = DateTime.Now,
                    Creator     = User.Identity.Name,
                    Key         = model.LoginName
                };
                MethodReturnResult rst = await client.AddAsync(u);

                if (rst.Code == 0)
                {
                    rst.Message = string.Format(StringResource.User_SaveUser_Success, u.Key);
                }
                return(Json(rst));
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                User u = new User()
                {
                    Key      = model.LoginName,
                    Password = model.Password,
                    UserName = model.UserName
                };

                using (UserServiceClient client = new UserServiceClient())
                {
                    MethodReturnResult result = await client.AddAsync(u);

                    if (result.Code == 0)
                    {
                        SignIn(u, isPersistent: false);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
            }
            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return(View(model));
        }