Exemplo n.º 1
0
 public TaskResult<UserDetail> GetUserDetails(int userId)
 {
     TaskResult<UserDetail> result = null;
     try
     {
        User uentity=  _userRepository.GetSingle(u => u.Id == userId);
        UserDetail detail = new UserDetail { Id = uentity.Id, USerName = uentity.UserName };
        result = new TaskResult<UserDetail>() { Data = detail, state = StatusState.DoneState };
     }
     catch(Exception e)
     {
         Logger.Instance.LogException(e);
         result = new TaskResult<UserDetail>() { Data = null, state = StatusState.CancelState };
     }
     return result;
 }
        public TaskResult<UserDetail> TryLoginUser(UserDetail user)
        {
            TaskResult<UserDetail> result=null;
            HttpClient client = GetHTTPClient();
            var content = new ObjectContent(typeof(UserDetail),user, new JsonMediaTypeFormatter());
            HttpResponseMessage response = client.PostAsync("api/User/Validate",content).Result;

            if (response.IsSuccessStatusCode)
            {
                result = response.Content.ReadAsAsync<TaskResult<UserDetail>>().Result;

            }
            else
            {
                result = new TaskResult<UserDetail> { state = StatusState.CancelState, Data = null };
            }
            return result;
        }
Exemplo n.º 3
0
        public TaskResult<UserDetail> Validate(UserDetail user)
        {
            TaskResult<UserDetail> result;
            try
            {
                var _user = _userRepository.GetSingle((x) => x.UserName == user.USerName && x.Password == user.Password);
                result = new TaskResult<UserDetail> { state = StatusState.DoneState, Data = new UserDetail { Id=_user.Id,USerName=_user.UserName} };
            }
            catch(Exception e)
            {
                Logger.Instance.LogException(e);
                result = new TaskResult<UserDetail> { state = StatusState.CancelState, Data = null };
            }

            return result;
        }
Exemplo n.º 4
0
        public TaskResult<bool> SaveUser(UserDetail user)
        {
            TaskResult<bool> result = null ;
            try
            {
                if (user.Id == null)//create
                {
                    _userRepository.Insert(new User { DateCreated = DateTime.Now, Password = user.Password, UserName = user.USerName });
                    _userRepository.SaveChanges();
                    result = new TaskResult<bool> { state = StatusState.DoneState, Data = true };
                }
                else//update
                {

                }
            }
            catch(Exception e)
            {
                Logger.Instance.LogException(e);
                result = new TaskResult<bool> { state = StatusState.DoneState, Data = false };
            }
            return result;
        }