Beispiel #1
0
        public async Task <ActionResult> Edit([Bind(Include = "ID,SelectionQuestionID,AssessorID,ProgApplicationID,AssignedScore,CreatedDate,isDeleted,TimeStamp,OrganizationID")] SelectionAnswer selectionAnswer)
        {
            if (ModelState.IsValid)
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(baseurl);
                    client.DefaultRequestHeaders.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                    HttpResponseMessage Res = await client.PutAsJsonAsync($"api/SelectionAnswers/{selectionAnswer.ID}", selectionAnswer);

                    if (Res.IsSuccessStatusCode)
                    {
                        this.AddNotification("SelectionAnswers information modified successfully", NotificationType.SUCCESS);
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        this.AddNotification("SelectionAnswers information cannot be modified at this time. Please contact Administrator", NotificationType.ERROR);
                        return(View());
                    }
                }
            }

            ViewBag.OrganizationID = await OrganizationSelectListByModel(token, selectionAnswer.OrganizationID);

            ViewBag.AssessorID = await AssessorSelectListByModel(token, selectionAnswer.AssessorID);

            ViewBag.SelectionQuestionID = await SelectionQuestionSelectListByModel(token, selectionAnswer.SelectionQuestionID);

            ViewBag.ProgApplicationID = await ProgApplicationSelectListByModel(token, selectionAnswer.ProgApplicationID);

            return(View(selectionAnswer));
        }
Beispiel #2
0
        public async Task <ActionResult> Details(int?id)
        {
            #region USERVALIDATION
            token = (string)(Session["accessToken"]);
            string userID = (string)(Session["UserID"]);
            #endregion
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            List <SelectionAnswer> selectionAnswer = new List <SelectionAnswer>();


            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(baseurl);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                HttpResponseMessage Res = await client.GetAsync($"api/SelectionAnswers/{id}");

                if (Res.IsSuccessStatusCode)
                {
                    var             SelectionAnswerResponse = Res.Content.ReadAsStringAsync().Result;
                    SelectionAnswer mySelectionAnswer       = JsonConvert.DeserializeObject <SelectionAnswer>(SelectionAnswerResponse);
                    return(View(mySelectionAnswer));
                }
                else
                {
                    this.AddNotification("Unable to display SelectionAnswers information,please contact Administrator" + Res, NotificationType.ERROR);
                    return(View());
                }
            }
        }
        private static SelectionAnswer GenerateSelectionAnswer(FormCollection collection, Evaluation evaluation, Question question, string aux)
        {
            SelectionAnswer s = new SelectionAnswer();

            s.Evaluation_Id = evaluation.Id;
            s.CreationDate  = DateTime.Now;
            s.Option_Id     = Int32.Parse(collection["q[" + question.Id + aux + "]"]);
            int value = new OptionsServices().GetById(s.Option_Id).Value;

            if (!question.Positive)
            {
                value = (new OptionsServices().GetOptionsCount(question.Category.Questionnaire_Id.Value) + 1) - value;
                int questionnaire = (evaluation.Test.Questionnaire_Id.HasValue) ? evaluation.Test.Questionnaire_Id.Value : GetQuestionnaireIdFromEvaluation(evaluation);
                s.Option_Id = new OptionsServices().GetByValue(value, questionnaire).Id;
            }
            s.Question_Id = question.Id;
            return(s);
        }
Beispiel #4
0
        public async Task <ActionResult> Create([Bind(Include = "ID,SelectionQuestionID,AssessorID,ProgApplicationID,AssignedScore,CreatedDate,isDeleted,TimeStamp,OrganizationID")] SelectionAnswer selectionAnswer)
        {
            #region USERVALIDATION
            token = (string)(Session["accessToken"]);
            string userID = (string)(Session["UserID"]);
            #endregion
            if (ModelState.IsValid)
            {
                selectionAnswer.CreatedDate = DateTime.Now;
                selectionAnswer.isDeleted   = false;
                selectionAnswer.TimeStamp   = DateTime.Now;

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(baseurl);
                    client.DefaultRequestHeaders.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                    HttpResponseMessage Res = await client.PostAsJsonAsync("api/SelectionAnswers", selectionAnswer);

                    if (Res.IsSuccessStatusCode)
                    {
                        this.AddNotification("SelectionAnswer created successfully", NotificationType.SUCCESS);
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        this.AddNotification("SelectionAnswer cannot be created at this time. Please contact Administrator" + Res, NotificationType.ERROR);
                        return(View());
                    }
                }
            }
            ViewBag.OrganizationID = await OrganizationSelectListByModel(token, selectionAnswer.OrganizationID);

            ViewBag.AssessorID = await AssessorSelectListByModel(token, selectionAnswer.AssessorID);

            ViewBag.SelectionQuestionID = await SelectionQuestionSelectListByModel(token, selectionAnswer.SelectionQuestionID);

            ViewBag.ProgApplicationID = await ProgApplicationSelectListByModel(token, selectionAnswer.ProgApplicationID);

            return(View(selectionAnswer));
        }
        private static void InsertSelectionAnswer(FormCollection collection, Evaluation evaluation, Question question, string aux)
        {
            SelectionAnswer s = GenerateSelectionAnswer(collection, evaluation, question, aux);

            new SelectionAnswersServices().Add(s);
        }