Beispiel #1
0
        private ExamPaperViewModel assignGradesAndSubjectsListToModel(ExamPaperViewModel examPaperViewModel)
        {
            var grades          = HttpDataProvider.GetData <List <dynamic> >("grade/all");
            var gradesListItems = new List <SelectListItem>();

            grades.ForEach(delegate(dynamic grade)
            {
                gradesListItems.Add(new SelectListItem {
                    Value = grade.Id, Text = grade.GradeName
                });
            });

            examPaperViewModel.Grades = gradesListItems;

            var subjects          = HttpDataProvider.GetData <List <dynamic> >("subject/all");
            var subjectsListItems = new List <SelectListItem>();

            subjects.ForEach(delegate(dynamic subject)
            {
                subjectsListItems.Add(new SelectListItem {
                    Value = subject.Id, Text = subject.SubjectName
                });
            });

            examPaperViewModel.Subjects = subjectsListItems;

            return(examPaperViewModel);
        }
Beispiel #2
0
        public ActionResult Index()
        {
            var examPaperViewModel = new ExamPaperViewModel();

            // Todo: Get Values from Db
            examPaperViewModel.Grades = new List <SelectListItem>()
            {
                new SelectListItem {
                    Text = "Introductory", Value = "1"
                }
            };

            examPaperViewModel.Subjects = new List <SelectListItem>()
            {
                new SelectListItem {
                    Text = "Science", Value = "1"
                }
            };

            return(View(examPaperViewModel));
        }
Beispiel #3
0
        public async Task <ActionResult> UploadAsync(CancellationToken cancellationToken, ExamPaperViewModel model)
        {
            var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).AuthorizeAsync(cancellationToken);

            if (result.Credential != null)
            {
                if ((TempData["isInitialPost"] != null) && (bool)TempData["isInitialPost"])
                {
                    model = (ExamPaperViewModel)TempData["examViewModel"];
                    TempData.Remove("examViewModel");
                    TempData.Remove("isInitialPost");
                }

                var service = new DriveService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = result.Credential,
                    ApplicationName       = ApplicationName
                });

                var file = new File()
                {
                    Title    = model.UploadFile.FileName,
                    MimeType = model.UploadFile.ContentType
                };

                try
                {
                    FilesResource.InsertMediaUpload uploadRequest = service.Files.Insert(file, model.UploadFile.InputStream, file.MimeType);
                    uploadRequest.ChunkSize = 256 * 1024;
                    var awList = await uploadRequest.UploadAsync();

                    var uploadResponse = uploadRequest.ResponseBody;

                    var examDetails = new {
                        PaperName   = model.PaperName,
                        SubjectId   = model.SelectedSubject,
                        GradeId     = model.SelectedGrade,
                        Year        = model.Year.ToString(),
                        HasAnswers  = model.HasAnswers,
                        FileStoreId = uploadResponse.Id
                    };

                    var createFileResponse = HttpDataProvider.PostAndReturn <dynamic, dynamic>("exam/create", examDetails);
                }
                catch (Exception ex)
                {
                    // Todo: Log errors and show friendly error
                }

                model = assignGradesAndSubjectsListToModel(model);
                return(View("Index", model));
            }
            else
            {
                TempData.Add("examViewModel", model);
                TempData.Add("isInitialPost", true);
                return(new RedirectResult(result.RedirectUri));
            }
        }