public async Task <IActionResult> Save(List <AssessmentFirstLangCreateTestDetailVm> vm)
        {
            var    questionsToAdd = new List <Question>();
            string fullLink       = $"{baseUri}/Assessment/{2}";
            var    langAssessment = WebApiService.GetApiResult <Assessment>(fullLink);

            try
            {
                foreach (var question in vm)
                {
                    if (question.IsToBeAdded)
                    {
                        var questionToAdd = WebApiService.GetApiResult <Question>($"{baseUri}/Question/{question.QuestionId}");
                        questionsToAdd.Add(questionToAdd);
                    }
                }

                var assessment = new AssessmentDetail()
                {
                    AssessmentTitle = $"{langAssessment.AssessmentTitle}, {DateTime.Now.Date}",
                    Questions       = questionsToAdd,
                    AssessmentId    = 2,
                    Assessment      = langAssessment
                };
                await WebApiService.PostCallApi <AssessmentDetail, AssessmentDetail>($"{baseUri}/assessmentdetail", assessment);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Add(SchoolUserCategoryDetailViewModel schoolUserCategoryDetailViewModel)
        {
            string fullLink = $"{baseUri}/SchoolUserCategory";

            SchoolUserCategory schoolUserCategory = new SchoolUserCategory
            {
                Category = schoolUserCategoryDetailViewModel.Category
            };

            await WebApiService.PostCallApi <SchoolUserCategory, SchoolUserCategory>(fullLink, schoolUserCategory);

            return(RedirectToAction("Index", "UserCategory"));
        }
        public async Task <IActionResult> Add(ClassGroupDetailViewModel classGroupDetailViewModel)
        {
            string fullLink      = $"{baseUri}/ClassGroup";
            string yeargradeLink = $"{baseUri}/YearGrade/{classGroupDetailViewModel.SelectedYearGradeId}";

            YearGrade yearGrade = WebApiService.GetApiResult <YearGrade>(yeargradeLink);

            ClassGroup classGroup = new ClassGroup
            {
                ClassGroupName = classGroupDetailViewModel.ClassGroupName,
                YearGrade      = null,
                YearGradeId    = yearGrade.Id
            };

            await WebApiService.PostCallApi <ClassGroup, ClassGroup>(fullLink, classGroup);

            return(RedirectToAction("Index", "Classgroup"));
        }
        public async Task <IActionResult> Save(LangFirstQuestionDetailVm viewModel, IFormFile picture)
        {
            if (viewModel.Id != 0)
            {
                var categoryLink = $"{baseUri}/QuestionCategory/{2}";
                var category     = WebApiService.GetApiResult <QuestionCategory>(categoryLink);

                var answerLink = $"{baseUri}/Answer/{viewModel.AnswerId}";
                var answer     = new Answer()
                {
                    Id         = viewModel.AnswerId,
                    LangAnswer = viewModel.Answer
                };
                answer = await WebApiService.PutCallApi <Answer, Answer>(answerLink, answer);

                List <Feedback> feedbackList = new List <Feedback>();
                feedbackList.Add(new Feedback()
                {
                    Id = viewModel.FirstFeedbackId, Description = viewModel.FirstFeedback, QuestionId = viewModel.Id
                });
                feedbackList.Add(new Feedback()
                {
                    Id = viewModel.SecondFeedbackId, Description = viewModel.SecondFeedback, QuestionId = viewModel.Id
                });
                var questionLink = $"{baseUri}/Question/{viewModel.Id}";
                var question     = new Question()
                {
                    Id                 = viewModel.Id,
                    QuestionTitle      = viewModel.QuestionTitle,
                    FileName           = _imageServices.UploadImage(picture, "images/LangFirstQuestions"),
                    AnswerId           = answer.Id,
                    Answer             = answer,
                    QuestionCategory   = category,
                    QuestionCategoryId = category.Id,
                    Feedback           = feedbackList
                };
                question = await WebApiService.PutCallApi <Question, Question>(questionLink, question);

                var feedbackLink = $"{baseUri}/Feedback";
                await WebApiService.PutCallApi <Feedback, Feedback>($"{feedbackLink}/{viewModel.FirstFeedbackId}", feedbackList.ElementAt(0));

                await WebApiService.PutCallApi <Feedback, Feedback>($"{feedbackLink}/{viewModel.SecondFeedbackId}", feedbackList.ElementAt(1));

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                var categoryLink = $"{baseUri}/QuestionCategory/{2}";
                var category     = WebApiService.GetApiResult <QuestionCategory>(categoryLink);

                var answerLink = $"{baseUri}/Answer";
                var answer     = new Answer()
                {
                    LangAnswer = viewModel.Answer
                };
                //var seededAnswer = await WebApiService.PostCallApi<Answer, Answer>(answerLink, answer);
                answer.Id = 0;

                List <Feedback> feedbackList = new List <Feedback>();
                feedbackList.Add(new Feedback()
                {
                    Description = viewModel.FirstFeedback
                });
                feedbackList.Add(new Feedback()
                {
                    Description = viewModel.SecondFeedback
                });
                var questionLink = $"{baseUri}/Question";
                var question     = new Question()
                {
                    QuestionTitle    = viewModel.QuestionTitle,
                    FileName         = _imageServices.UploadImage(picture, "images/LangFirstQuestions"),
                    Answer           = answer,
                    QuestionCategory = category,
                    Feedback         = feedbackList
                };
                await WebApiService.PostCallApi <Question, Question>(questionLink, question);


                return(RedirectToAction(nameof(Index)));
            }
        }
Example #5
0
        public async Task <IActionResult> Save(LangQuestionsDetailVm viewModel)
        {
            //ADJUST BOTH FOR QUESTIONCATEGORY (CAN QUESTIONCATEGORY BE CHANGED?)
            if (viewModel.Id != 0)
            {
                var categoryLink = $"{baseUri}/QuestionCategory/{viewModel.QuestionCategoryId}";
                var category     = WebApiService.GetApiResult <QuestionCategory>(categoryLink);

                var answerLink = $"{baseUri}/Answer/{viewModel.AnswerId}";
                var answer     = new Answer()
                {
                    Id         = viewModel.AnswerId,
                    LangAnswer = viewModel.Answer
                };
                answer = await WebApiService.PutCallApi <Answer, Answer>(answerLink, answer);

                List <Feedback> feedbackList = new List <Feedback>();
                feedbackList.Add(new Feedback()
                {
                    Id = viewModel.FirstFeedbackId, Description = viewModel.FirstFeedback, QuestionId = viewModel.Id
                });
                feedbackList.Add(new Feedback()
                {
                    Id = viewModel.SecondFeedbackId, Description = viewModel.SecondFeedback, QuestionId = viewModel.Id
                });
                var questionLink = $"{baseUri}/Question/{viewModel.Id}";
                var question     = new Question()
                {
                    Id                 = viewModel.Id,
                    QuestionTitle      = viewModel.QuestionTitle,
                    Description        = viewModel.Description,
                    AnswerId           = answer.Id,
                    Answer             = answer,
                    QuestionCategory   = category,
                    QuestionCategoryId = category.Id,
                    Feedback           = feedbackList
                };
                question = await WebApiService.PutCallApi <Question, Question>(questionLink, question);

                var feedbackLink = $"{baseUri}/Feedback";
                await WebApiService.PutCallApi <Feedback, Feedback>($"{feedbackLink}/{viewModel.FirstFeedbackId}", feedbackList.ElementAt(0));

                await WebApiService.PutCallApi <Feedback, Feedback>($"{feedbackLink}/{viewModel.SecondFeedbackId}", feedbackList.ElementAt(1));

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                var categoryLink = $"{baseUri}/QuestionCategory/{viewModel.QuestionCategoryId}";
                var category     = WebApiService.GetApiResult <QuestionCategory>(categoryLink);

                var answerLink = $"{baseUri}/Answer";
                var answer     = new Answer()
                {
                    LangAnswer = viewModel.Answer
                };

                answer.Id = 0;

                List <Feedback> feedbackList = new List <Feedback>();
                feedbackList.Add(new Feedback()
                {
                    Description = viewModel.FirstFeedback
                });
                feedbackList.Add(new Feedback()
                {
                    Description = viewModel.SecondFeedback
                });
                var questionLink = $"{baseUri}/Question";
                var question     = new Question()
                {
                    QuestionTitle    = viewModel.QuestionTitle,
                    Description      = viewModel.Description,
                    Answer           = answer,
                    QuestionCategory = category,
                    Feedback         = feedbackList
                };
                await WebApiService.PostCallApi <Question, Question>(questionLink, question);


                return(RedirectToAction(nameof(Index)));
            }
        }