public HttpResponseMessage AddUser([FromBody] UserModel userModel) { ApiResultViewModel result = new ApiResultViewModel(); if (!ModelState.IsValid) { result.Result = false; result.Status = ResponseCode.Fail.ToString(); result.Message = AllShared.GetModelStateError(ModelState); return(Request.CreateResponse(HttpStatusCode.OK, result)); } //取得加密密碼 userModel.UserPwd = userModel.UserPwd.GetMD5(); bool IsSuccess = userRepository.AddUser(userModel); if (IsSuccess) { result.Result = true; result.Status = ResponseCode.Success.ToString(); result.Message = "新增成功!!!"; } else { result.Result = false; result.Status = ResponseCode.Fail.ToString(); result.Message = "新增資料時發生錯誤!!!"; } return(Request.CreateResponse(HttpStatusCode.OK, result)); //HttpResponseMessage httpRequestMessage = Request.CreateResponse(HttpStatusCode.OK, result); //return Request.CreateResponse(httpRequestMessage); }
public HttpResponseMessage AddArticle([FromBody] ArticleModel articleModel) { ApiResultViewModel result = new ApiResultViewModel(); //驗證欄位資訊 if (!ModelState.IsValid) { result.Result = false; result.Status = ResponseCode.Fail.ToString(); result.Message = AllShared.GetModelStateError(ModelState); return(Request.CreateResponse(HttpStatusCode.OK, result)); } //取得使用者ID string UserID = JWTShared.GetUserID(Request.Headers.Authorization.Parameter); articleModel.UID = UserID; bool IsSuccess = articleRepository.AddArticle(articleModel); if (IsSuccess) { result.Result = true; result.Status = ResponseCode.Success.ToString(); result.Message = "新增成功!!!"; } else { result.Result = false; result.Status = ResponseCode.Fail.ToString(); result.Message = "新增資料時發生錯誤!!!"; } return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public HttpResponseMessage UpdateArticle(string Id, [FromBody] ArticleUpdateModel UpdateInfo) { ApiResultViewModel result = new ApiResultViewModel(); if (!ModelState.IsValid) { result.Result = false; result.Status = ResponseCode.Fail.ToString(); result.Message = AllShared.GetModelStateError(ModelState); return(Request.CreateResponse(HttpStatusCode.OK, result)); } if (UpdateInfo == null) { result.Result = false; result.Status = ResponseCode.Fail.ToString(); result.Message = "無修改資料相關參數"; return(Request.CreateResponse(HttpStatusCode.OK, result)); } //取得使用者ID string UserID = JWTShared.GetUserID(Request.Headers.Authorization.Parameter); ArticleViewModel ArticleViewModel = articleRepository.GetArticle(Id, UserID); if (UpdateInfo.Title == null) { UpdateInfo.Title = ArticleViewModel.Title; } if (UpdateInfo.Content == null) { UpdateInfo.Content = ArticleViewModel.Content; } if (ArticleViewModel == null) { result.Result = false; result.Status = ResponseCode.Fail.ToString(); result.Message = "查無此文章資料!!!"; return(Request.CreateResponse(HttpStatusCode.OK, result)); } bool IsSuccess = articleRepository.UpdateArticle(Id, UserID, UpdateInfo); if (IsSuccess) { result.Result = true; result.Status = ResponseCode.Success.ToString(); result.Message = "修改成功!!!"; } else { result.Result = false; result.Status = ResponseCode.Fail.ToString(); result.Message = "修改文章資料發生錯誤!!!"; } return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public IHttpActionResult UpdateUser(string Id, [FromBody] UserUpdateModel userInfo) { ApiResultViewModel result = new ApiResultViewModel(); if (!ModelState.IsValid) { result.Result = false; result.Status = ResponseCode.Fail.ToString(); result.Message = AllShared.GetModelStateError(ModelState); return(Ok(result)); } if (userInfo == null) { result.Result = false; result.Status = ResponseCode.Fail.ToString(); result.Message = "無修改資料相關參數"; return(Ok(result)); } //取得使用者ID //string UserID = JWTShared.GetUserID(Request.Headers.Authorization.Parameter); //if (Id != UserID) //{ // result.Result = false; // result.Status = ResponseCode.Fail.ToString(); // result.Message = "錯誤的使用者ID"; // return Ok(result); //} bool IsSuccess = userRepository.UpdateUser(Id, userInfo); if (IsSuccess) { result.Result = true; result.Status = ResponseCode.Success.ToString(); result.Message = "更新資料成功!!!"; } else { result.Result = false; result.Status = ResponseCode.Fail.ToString(); result.Message = "更新資料失敗,查無使用者資訊!!!"; } return(Ok(result)); }