Example #1
0
        public IActionResult UpdateUser([FromBody] UpdateUserDto updateUserDto, string id)
        {
            var userID = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            // Validate
            ValidateResultDto check = _validate.CreateNewUser(updateUserDto);

            if (check.code != 0)
            {
                return(StatusCode(check.code, new { message = check.message, code = 400, data = "" }));
            }
            ;
            if (updateUserDto.STATUS == "INACTIVE")
            {
                bool checkIncharge = _userRepository.CheckTsrInCharge(id);
                if (checkIncharge)
                {
                    return(StatusCode(400, new
                    {
                        code = 400,
                        message = "Vui lòng phân công lại KH trước!",
                        data = ""
                    }));
                }
            }
            // Check user exist
            // chua co ldap, coi nhu la dc roi
            // IActionResult result = CheckUserLDAP (user.USER_NAME);
            bool result = true;

            if (!result)
            {
                return(StatusCode(400, new { message = "User not in ldap!", code = 400, data = "" }));;
            }
            Guid newId = _userRepository.UpdateUser(updateUserDto, id, userID);

            if (newId == new Guid("00000000-0000-0000-0000-000000000000"))
            {
                return(Ok(new ResponseForm <Guid>(newId, "username exist", 400)));
            }
            return(Ok(new ResponseForm <Guid>(newId, "ok", 200)));
        }