コード例 #1
0
        public async Task <ActionResult> Register(BeSafeModels.User user)
        {
            if (ModelState.IsValid)
            {
                BeSafeEntities.User LogedinUser = UserBusinessLogic.UserValidation(user.UserName, user.Password).Result;
                if (LogedinUser == null)
                {
                    var userEntity = mapUserModelToEntity.ConvertObject(user);
                    userEntity.CreatedDate = DateTime.Now;
                    LogedinUser            = await UserBusinessLogic.AddUser(userEntity);
                }
                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, LogedinUser.UserName),
                    new Claim(ClaimTypes.Sid, LogedinUser.ID.ToString()),
                    new Claim(ClaimTypes.Email, LogedinUser.Email)
                };
                var claimsIdentity = new ClaimsIdentity(claims, "Login");

                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));

                return(RedirectToAction("Index", "Admin"));
            }
            return(View(user));
        }
コード例 #2
0
        public ActionResult CreateUser([FromBody] User data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                userBusinessLogic.AddUser(data);
                return(Ok(mapper.Map <UserDTO>(data)));
            }
            catch (UserException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
コード例 #3
0
 public void AddUserOkTest()
 {
     mockUserRepo.Setup(x => x.Insert(It.IsAny <User>())).Callback <User>(x => userList.Add(userWithAllData));
     userBLWithoutTeamBL.AddUser(userWithAllData);
     mockUserRepo.Verify(x => x.Insert(It.IsAny <User>()), Times.Once());
 }
コード例 #4
0
 public void AddUser_ExpectedParameters_Ok()
 {
     userBusinessLogic.AddUser(user);
 }