public HttpResponseMessage Post([FromBody] PostLogs value) { try { var token = Request.Headers.Authorization.Parameter; if (value == null || (IsMe != null && IsMe.UserID == "")) { Msg = Request.CreateResponse(HttpStatusCode.Forbidden); } else if (!reCaptchaController.IsReCaptchValid(token)) { Msg = Request.CreateResponse(HttpStatusCode.Unauthorized); } else { var questionID = value.QuestionID; var answerID = value.AnswerID; if (answerID == null || answerID == 0) { var q = (new Questions()).GetQuestionData(Utilities.ToString(questionID)).FirstOrDefault(); if (q == null) { q = new Questions(); } q.QuestionID = questionID; q.QuestionTitle = value.OriginalTitile; q.QuestionDesc = value.OriginalDesc; bool stamp = (IsMe.UserID == q.UserID); q.MngQuestionData(dbUtilities.opUPDATE, ref q, stamp); } else { var a = (new Answers()).GetAnswerData(Utilities.ToString(questionID), Utilities.ToString(answerID)).FirstOrDefault(); if (a == null) { a = new Answers(); } a.QuestionID = questionID; a.AnswerID = Utilities.ToInt(answerID); a.AnswerDesc = value.OriginalDesc; bool stamp = (IsMe.UserID == a.UserID); a.MngAnswerData(dbUtilities.opUPDATE, a, stamp); } if (Log.MngLogData(dbUtilities.opINSERT, value)) { Msg = Request.CreateResponse(HttpStatusCode.Created); } else { Msg = Request.CreateResponse(HttpStatusCode.BadRequest); } } } catch (Exception) { Msg = Request.CreateResponse(HttpStatusCode.NotFound); } return(Msg); }
public LogController() { Log = new PostLogs(); IsMe = (Membership)HttpContext.Current.Session["ISME"]; if (IsMe == null) { IsMe = new Membership(); } }
public HttpResponseMessage Put(int key, [FromBody] Questions value) { int op = 0; try { var token = Request.Headers.Authorization.Parameter; if (value == null || (IsMe != null && IsMe.UserID == "")) { Msg = Request.CreateResponse(HttpStatusCode.Forbidden); } else if (!reCaptchaController.IsReCaptchValid(token)) { Msg = Request.CreateResponse(HttpStatusCode.Unauthorized); } else { value.QuestionID = key; var log = new PostLogs(); log.QuestionID = key; log.OriginalTitile = value.QuestionTitle; log.OriginalDesc = value.QuestionDesc; if (Question.MngQuestionData(dbUtilities.opUPDATE, ref value, false)) { log.MngLogData(dbUtilities.opINSERT, log); var qID = value.QuestionID; Question.MngQuestionUser(dbUtilities.opDELETE, qID); foreach (Membership mb in value.UserList) { Question.MngQuestionUser(dbUtilities.opINSERT, qID, mb.UserID); } Msg = Request.CreateResponse(HttpStatusCode.Created, value); } else { Msg = Request.CreateResponse(HttpStatusCode.BadRequest); } } } catch (Exception) { Msg = Request.CreateResponse(HttpStatusCode.NotFound); } return(Msg); }
public HttpResponseMessage Put(int key, [FromBody] Answers value) { int op = 0; try { if (key <= 0 && value == null) { Msg = Request.CreateResponse(HttpStatusCode.Forbidden); } else { op = (key == 0) ? dbUtilities.opINSERT : dbUtilities.opUPDATE; var ans = Answer.GetAnswerData("", Utilities.ToString(key)).FirstOrDefault(); if (ans != null && ans.AnswerID != 0) { if (Answer.MngAnswerData(op, value)) { var log = new PostLogs(); log.QuestionID = ans.QuestionID; log.AnswerID = ans.AnswerID; log.OriginalDesc = ans.AnswerDesc; Msg = Request.CreateResponse(HttpStatusCode.OK); log.MngLogData(dbUtilities.opINSERT, log); } else { Msg = Request.CreateResponse(HttpStatusCode.NotModified); } } else { Msg = Request.CreateResponse(HttpStatusCode.Forbidden); } } } catch (Exception) { Msg = Request.CreateResponse(HttpStatusCode.NotFound); } return(Msg); }