public IHttpActionResult GetUser()
        {
            var identity = (ClaimsIdentity)User.Identity;
            var userId   = identity.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var user     = UserBl.GetUser(Convert.ToInt32(userId));

            if (user != null)
            {
                return(Ok(user));
            }
            return(BadRequest());
        }
        public ActionResult <UserDto> Get(string id)
        {
            // 參數檢查
            var validationResults = new List <ValidationResult>();

            if (string.IsNullOrWhiteSpace(id))
            {
                validationResults.Add(new ValidationResult($"參數不合法", new[] { nameof(id) }));
            }
            if (validationResults.Any())
            {
                return(BadRequest(validationResults));
            }

            var result = _userBl.GetUser(id);

            if (result is null)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
Esempio n. 3
0
 public User GetUser(int id)
 {
     return(_userBl.GetUser(id));
 }