Beispiel #1
0
        public HttpResponseMessage UpdateData(string user_id, [FromBody] preg_user dataUpdate)
        {
            try
            {
                if (!dataUpdate.DeepEquals(new preg_user()))
                {
                    preg_user user = new preg_user();
                    user = userdao.GetUserByID(Convert.ToInt32(user_id)).FirstOrDefault();
                    if (user == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND));
                    }
                    if (dataUpdate.password != null)
                    {
                        user.password = SysMethod.MD5Hash(dataUpdate.password);
                    }
                    if (dataUpdate.email != null)
                    {
                        user.email = dataUpdate.email;
                    }
                    if (dataUpdate.first_name != null)
                    {
                        user.first_name = dataUpdate.first_name;
                    }
                    if (dataUpdate.last_name != null)
                    {
                        user.last_name = dataUpdate.last_name;
                    }
                    if (dataUpdate.you_are_the != null)
                    {
                        user.you_are_the = dataUpdate.you_are_the;
                    }
                    if (dataUpdate.location != null)
                    {
                        user.location = dataUpdate.location;
                    }
                    if (dataUpdate.status != null)
                    {
                        user.status = dataUpdate.status;
                    }
                    if (dataUpdate.avatar != null)
                    {
                        user.avatar = dataUpdate.avatar;
                    }

                    userdao.UpdateData(user);
                    return(Request.CreateResponse(HttpStatusCode.Accepted, SysConst.DATA_UPDATE_SUCCESS));
                }
                else
                {
                    HttpError err = new HttpError(SysConst.DATA_NOT_EMPTY);
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, err));
                }
            }
            catch (Exception ex)
            {
                HttpError err = new HttpError(ex.Message);
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, err));
            }
        }
 public HttpResponseMessage Get([FromUri] preg_user data)
 {
     try
     {
         if (!data.DeepEquals(new preg_user()) && data.password == null)
         {
             IEnumerable <preg_user> results = dao.GetUsersByParams(data);
             if (results.Count() > 0)
             {
                 foreach (var result in results)
                 {
                     result.password = null;
                 }
                 return(Request.CreateResponse(HttpStatusCode.OK, results));
             }
             else
             {
                 HttpError err = new HttpError(SysConst.DATA_NOT_FOUND);
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, err));
             }
         }
         else
         {
             IEnumerable <preg_user> results = dao.GetListUser();
             if (results.Count() > 0)
             {
                 foreach (var result in results)
                 {
                     result.password = null;
                 }
                 return(Request.CreateResponse(HttpStatusCode.OK, results));
             }
             else
             {
                 HttpError err = new HttpError(SysConst.DATA_NOT_FOUND);
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, err));
             }
         }
     }
     catch (Exception ex)
     {
         HttpError err = new HttpError(ex.Message);
         return(Request.CreateErrorResponse(HttpStatusCode.NotFound, err));
     }
 }