示例#1
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));
            }
        }
示例#2
0
        public ActionResult Grade(GradeViewModel model)
        {
            try
            {
                var gradeDetails      = new { GradeName = model.GradeName };
                var saveGradeResponse = HttpDataProvider.PostAndReturn <dynamic, dynamic>("grade/create", gradeDetails);
            }
            catch (Exception ex)
            {
            }

            return(View(model));
        }
示例#3
0
        public ActionResult Subject(SubjectViewModel model)
        {
            try
            {
                var subjectDetails    = new { SubjectName = model.SubjectName };
                var saveGradeResponse = HttpDataProvider.PostAndReturn <dynamic, dynamic>("subject/create", subjectDetails);
            }
            catch (Exception ex)
            {
            }

            return(View(model));
        }
示例#4
0
        public ActionResult Upload(string fileId)
        {
            var successList          = new List <Tuple <string, string> >();
            var failList             = new List <Tuple <string, string> >();
            var internalDataProvider = new HttpDataProvider(ConfigurationManager.AppSettings["InternalApiBaseUrl"]);
            var customers            = internalDataProvider.GetData <List <CustomerEntry> >("api/upload");

            if (customers.Any())
            {
                var externalDataProvider = new HttpDataProvider(ConfigurationManager.AppSettings["ExternalApiBaseUrl"]);
                var fileName             = Path.GetFileName(ConfigurationManager.AppSettings[fileId]);

                customers.ForEach(delegate(CustomerEntry customer)
                {
                    dynamic customerJson =
                        new
                    {
                        property = "Anushan",
                        customer = customer.FullName,
                        action   = "order created",
                        value    = customer.Value,
                        file     = fileName
                    };

                    var resultJson = externalDataProvider.PostAndReturn <dynamic, dynamic>("upload", customerJson);

                    if (resultJson.added == "true")
                    {
                        var addedCustomerEntry = externalDataProvider.GetData <dynamic>(string.Format("check?hash={0}", resultJson.hash));
                        successList.Add(new Tuple <string, string>(string.Format("Hash: {0}", addedCustomerEntry.hash), string.Format("Customer: {0}", addedCustomerEntry.customer)));
                    }
                    else
                    {
                        failList.Add(new Tuple <string, string>(customer.FullName, resultJson.errors));
                    }
                });
            }

            ViewBag.SuccessList = successList;
            ViewBag.FailList    = failList;

            return(View());
        }
示例#5
0
        public ActionResult Upload(string fileId)
        {
            var successList = new List<Tuple<string, string>>();
            var failList = new List<Tuple<string, string>>();
            var internalDataProvider = new HttpDataProvider(ConfigurationManager.AppSettings["InternalApiBaseUrl"]);
            var customers = internalDataProvider.GetData<List<CustomerEntry>>("api/upload");

            if (customers.Any())
            {
                var externalDataProvider = new HttpDataProvider(ConfigurationManager.AppSettings["ExternalApiBaseUrl"]);
                var fileName = Path.GetFileName(ConfigurationManager.AppSettings[fileId]);

                customers.ForEach(delegate(CustomerEntry customer)
                {
                    dynamic customerJson =
                        new
                        {
                            property = "Anushan",
                            customer = customer.FullName,
                            action = "order created",
                            value = customer.Value,
                            file = fileName
                        };

                    var resultJson = externalDataProvider.PostAndReturn<dynamic, dynamic>("upload", customerJson);

                    if (resultJson.added == "true")
                    {
                        var addedCustomerEntry = externalDataProvider.GetData<dynamic>(string.Format("check?hash={0}", resultJson.hash));
                        successList.Add(new Tuple<string, string>(string.Format("Hash: {0}", addedCustomerEntry.hash), string.Format("Customer: {0}", addedCustomerEntry.customer)));
                    }
                    else
                        failList.Add(new Tuple<string, string>(customer.FullName, resultJson.errors));
                });
            }

            ViewBag.SuccessList = successList;
            ViewBag.FailList = failList;

            return View();
        }
示例#6
0
        public ActionResult AddDrivePapersList(BulkViewModel model)
        {
            var examPapers = (List <dynamic>)Session["ICASPapers"];

            if (examPapers != null && examPapers.Count > 0)
            {
                try
                {
                    var createExamsListResponse = HttpDataProvider.PostAndReturn <List <dynamic>, List <int> >("exam/createlist", examPapers);
                    Session.Remove("ICASPapers");
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    // Todo: error handling
                }
            }
            // Todo: Error handling

            return(View("Index", model));
        }