Пример #1
0
        public async Task <IActionResult> Active(UpdateTokenModel <string> entityId)
        {
            // check modelstate
            if (!ModelState.IsValid)
            {
                string errorLangCode = ConstantConfig.WebApiResultMessage.Error;
                string errorMessage  = languageService.GetlangByKey(errorLangCode);
                return(BadRequest(new
                {
                    StatusCode = ConstantConfig.WebApiStatusCode.ModelInValid,
                    Message = errorMessage,
                    ModelErrors = GetModelErrors()
                }));
            }

            //find last modified
            Entities.WebCoreUser lastEntity = userService.GetById(entityId);

            if (lastEntity == null)
            {
                return(NotFound());
            }

            // check update token
            if (!lastEntity.UpdateToken.GetValueOrDefault().Equals(entityId.UpdateToken))
            {
                string errorLangCode = ConstantConfig.WebApiResultMessage.UpdateTokenNotMatch;
                string errorMessage  = languageService.GetlangByKey(errorLangCode);
                return(BadRequest(new
                {
                    StatusCode = ConstantConfig.WebApiStatusCode.Warning,
                    Message = errorMessage
                }));
            }

            bool result = await userService.Active(entityId);

            // if has any error
            if (!result)
            {
                string errorLangCode = ConstantConfig.WebApiResultMessage.Error;
                string errorMessage  = languageService.GetlangByKey(errorLangCode);
                return(BadRequest(new
                {
                    StatusCode = ConstantConfig.WebApiStatusCode.Error,
                    Message = errorMessage
                }));
            }

            return(Ok());
        }
Пример #2
0
 public IActionResult Enable([FromQuery] string dn,
                             [FromQuery] string samname)
 {
     if (!string.IsNullOrWhiteSpace(dn) && !string.IsNullOrWhiteSpace(samname))
     {
         var user = new ObjectResult(_userService.Active(dn, samname));
         if (user == null)
         {
             return(NoContent());
         }
         return(Ok(user));
     }
     return(BadRequest());
 }
        public async Task Active_ExistingGuidPassed_ReturnsTrueResult()
        {
            // Arrange
            Guid testGuid = new Guid("ab2bd817-98cd-4cf3-a80a-53ea0cd9c200");

            _mockUnitOfWork.Setup(x => x.UserRepository.GetUserActiveById(testGuid))
            .ReturnsAsync(new User
            {
                Id       = testGuid,
                UserName = "******"
            });

            _mockUnitOfWork.Setup(x => x.CommitAsync())
            .ReturnsAsync(true);

            // Act
            bool okResult = await _userService.Active(testGuid);

            // Assert
            _mockUnitOfWork.Verify(x => x.UserRepository.Delete(It.IsAny <User>()), Times.Once);

            Assert.True(okResult);
        }
Пример #4
0
        public async Task <ActionResult> Active(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(BadRequest(_config["Errors:Base:ModelInValid"]));
            }

            //Set Config
            SetConfig();

            //Active user
            var isOk = await _userService.Active(id);

            return(Ok(isOk));
        }
Пример #5
0
 public IActionResult Active(long id)
 {
     if (SessionHelper.GetSession <User>(HttpContext.Session, "Login") == null)
     {
         return(RedirectToAction("Login"));
     }
     else
     {
         try
         {
             var user = _userService.GetById(id);
             if (user != null)
             {
                 _userService.Active(id);
                 return(RedirectToAction("Index"));
             }
             return(StatusCode(404));
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Пример #6
0
 public Task <IResultModel> Active([BindRequired] Guid id)
 {
     return(_userService.Active(id));
 }