コード例 #1
0
 public HttpResponseMessage updateAnswer(GetAnswerModel getanswerMode)
 {
     try
     {
         MessageModel value = new MessageModel();
         value = authenticationUser(getanswerMode.authenticationUser);
         if (value.idMessage == (int)MessageCode.OkUser)
         {
             var q = context.Answers.Where(i => i.id == getanswerMode.answer.id).FirstOrDefault();
             q.answer = getanswerMode.answer.answer;
             q.active = getanswerMode.answer.active;
             context.SaveChanges();
             var message = Request.CreateResponse(HttpStatusCode.OK, (int)MessageCode.Savedata);
             return(message);
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.OK, value.idMessage.ToString()));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.OK, ex));
     }
 }
コード例 #2
0
        public async Task <IActionResult> Get(string id)
        {
            GetAnswerModel response = await _httpSender.SendGetAsync <GetAnswerModel>(AnswersRoot + "/" + id);

            if (response != null)
            {
                return(Ok(response));
            }
            else
            {
                return(BadRequest("There is no such post."));
            }
        }
コード例 #3
0
        public GetAnswerModel setAnswerKind1(GetAnswerModel getanswerMode)
        {
            try
            {
                MessageModel value = new MessageModel();
                value = authenticationUser(getanswerMode.authenticationUser);
                if (value.idMessage == (int)MessageCode.OkUser)
                {
                    if ((from i in context.Answers where i.answer == getanswerMode.answer.answer select i).FirstOrDefault() != null)
                    {
                        var messageduplicate = Request.CreateResponse(HttpStatusCode.OK, (int)MessageCode.DuplicateData);
                        return(new GetAnswerModel());
                    }
                    Questions q = context.Questions.Where(c => c.id == getanswerMode.answer.idQuestion).FirstOrDefault();
                    Answers   a = new Answers();
                    a.Questions = q;
                    a.answer    = getanswerMode.answer.answer;
                    a.active    = getanswerMode.answer.active;
                    a.kind      = 1;
                    context.Answers.Add(a);
                    context.SaveChanges();
                    ///select Answer id
                    int answerId = (from i in context.Answers where i.answer == a.answer select i.id).FirstOrDefault();


                    var message = Request.CreateResponse(HttpStatusCode.OK, (int)MessageCode.Savedata);
                    return(new GetAnswerModel());
                }
                else
                {
                    //return Request.CreateResponse(HttpStatusCode.OK, value.idMessage.ToString());
                    return(new GetAnswerModel());
                }
            }
            catch (Exception ex)
            {
                //return Request.CreateResponse(HttpStatusCode.OK, ex);
                return(new GetAnswerModel());
            }
        }