public async Task <List <DocumentSubmissionViewModel> > GetDocumentSubmissionData(int category, int subCategory, string studentEmpId)
        {
            List <DocumentSubmissionViewModel> listSubmission          = new List <DocumentSubmissionViewModel>();
            List <DocumentSubmissionViewModel> availableSubmissionList = new List <DocumentSubmissionViewModel>();

            using (var client = Common.GetHttpClient())
            {
                var Response = await client.GetAsync("api/DocumentType/GetAllByCategory?category=" + subCategory);

                if (Response.IsSuccessStatusCode)
                {
                    var typeList = JsonConvert.DeserializeObject <List <DocumentTypeViewModel> >(Response.Content.ReadAsStringAsync().Result);
                    if (!string.IsNullOrEmpty(studentEmpId))
                    {
                        HttpResponseMessage ResponseSubmission = await client.GetAsync("api/DocumentSubmission/GetDocumentSubmissionData?category=" + subCategory + "&studentEmpId=" + studentEmpId);

                        availableSubmissionList = JsonConvert.DeserializeObject <List <DocumentSubmissionViewModel> >(ResponseSubmission.Content.ReadAsStringAsync().Result);
                    }
                    foreach (var item in typeList)
                    {
                        var obj = availableSubmissionList.Where(x => x.DocumentTypeID == item.DocumentTypeID).FirstOrDefault();
                        if (obj == null)
                        {
                            obj = new DocumentSubmissionViewModel();
                            obj.DocumentTypeID = item.DocumentTypeID;
                        }
                        obj.DocumentType = item;

                        listSubmission.Add(obj);
                    }
                    return(listSubmission);
                }
                return(null);
            }
        }
Esempio n. 2
0
        public async Task <JsonResult> UploadDocument(string id = null, string userType = null)
        {
            HttpFileCollectionBase files = Request.Files;
            HttpPostedFileBase     file  = files[0];

            string[] testfiles;
            string   fname = "";

            if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
            {
                testfiles = file.FileName.Split(new char[] { '\\' });
                fname     = testfiles[testfiles.Length - 1];
            }
            else
            {
                fname = file.FileName;
            }
            DocumentSubmissionViewModel obj = new DocumentSubmissionViewModel();

            obj = await service.GetById(Convert.ToInt32(id));

            obj.DocumentType = await serviceType.GetById(obj.DocumentTypeID.Value);

            obj.PhysicalFileLocaiton  = fname;
            obj.UserType              = userType;
            obj.DigitalPathofDocument = await service.UploadDocuments(obj);

            obj.onlinesubmitted = true;
            return(new JsonResult {
                Data = obj, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public async Task <DocumentSubmissionViewModel> GetById(int id)
        {
            var documentSubmission = new DocumentSubmissionViewModel();

            using (var client = Common.GetHttpClient())
            {
                var Response = await client.GetAsync("api/documentSubmission/GetById/" + id);

                if (Response.IsSuccessStatusCode)
                {
                    return(JsonConvert.DeserializeObject <DocumentSubmissionViewModel>(Response.Content.ReadAsStringAsync().Result));
                }
                return(null);
            }
        }
        public async Task <DocumentSubmissionViewModel> Save(HttpContent collection)
        {
            DocumentSubmissionViewModel objDocumentSubmissionViewModel = new DocumentSubmissionViewModel();

            using (var client = Common.GetHttpClient())
            {
                var Response = await client.PostAsync("api/documentSubmission/Save", collection);

                if (Response.IsSuccessStatusCode == true)
                {
                    var returnData = Response.Content.ReadAsStringAsync().Result;

                    objDocumentSubmissionViewModel = JsonConvert.DeserializeObject <DocumentSubmissionViewModel>(returnData);
                }
                objDocumentSubmissionViewModel.IsRecordSaved = Response.IsSuccessStatusCode;
            }
            return(objDocumentSubmissionViewModel);
        }
        public async Task <string> UploadDocuments(DocumentSubmissionViewModel documentDetails)
        {
            string returrMessage = string.Empty;

            try
            {
                bool isValid = true;
                if (documentDetails.MaxFileSize < documentDetails.CurrentFileSize)
                {
                    returrMessage = "Max file size should be " + documentDetails.MaxFileSize.ToString();
                    isValid       = false;
                }
                else if (isValid == true && documentDetails.AllowedFileFormat != null && !string.IsNullOrEmpty(documentDetails.FileFormat) && documentDetails.AllowedFileFormat.Contains(documentDetails.FileFormat.ToLower()) == false)
                {
                    returrMessage = "Please upload documents in proper format.";
                    isValid       = false;
                }
                if (isValid)
                {
                    var stringContent = new StringContent("");                                    //= new StringContent(JsonConvert.SerializeObject(documentDetails).ToString(), Encoding.UTF8, "application/json");
                    DocumentSubmissionViewModel objDocumentSubmissionViewModel = documentDetails; //(DocumentSubmissionViewModel)(await Save(stringContent));
                    if (objDocumentSubmissionViewModel.IsRecordSaved)
                    {
                        string   fileName              = System.IO.Path.GetFileName(documentDetails.PhysicalFileLocaiton);
                        string   newFile               = documentDetails.DocumentType.DocumentTypeName + "_UserID_" + documentDetails.Enquiry_Id.ToString() + "_DocumentID_" + objDocumentSubmissionViewModel.DocumentSubmission_ID.ToString();
                        string[] splString             = fileName.Split('.');
                        string   uploadNewFileName     = newFile + "." + splString[1];
                        string   filePathTobeSaved     = "";
                        string   createDir             = string.Empty;
                        string   digitalPathofDocument = string.Empty;
                        string   baseurl               = HttpContext.Current.Server.MapPath("~/UploadDocuments");
                        //Create Document directory according to employee and there documents.
                        if (documentDetails.UserType == "Employee")
                        {
                            //Create documents for employee
                            documentDetails.DigitalPathofDocument = baseurl + "/Employees";
                            createDir = documentDetails.DigitalPathofDocument + "/" + documentDetails.DocumentType.DocumentTypeName;
                            CreateDirectoryIfNotExists(createDir);
                            filePathTobeSaved     = createDir + "/" + uploadNewFileName;
                            digitalPathofDocument = "~/UploadDocuments/Employees/" + documentDetails.DocumentType.DocumentTypeName + "/" + uploadNewFileName;

                            returrMessage = "Document uploaded successfully.";
                        }
                        else if (documentDetails.UserType == "Student")
                        {
                            //Create documents for Student
                            documentDetails.DigitalPathofDocument = baseurl + "/Students";
                            createDir = documentDetails.DigitalPathofDocument + "/" + documentDetails.DocumentType.DocumentTypeName;
                            CreateDirectoryIfNotExists(createDir);
                            filePathTobeSaved = createDir + "/" + uploadNewFileName;

                            digitalPathofDocument = "~/UploadDocuments/Students/" + documentDetails.DocumentType.DocumentTypeName + "/" + uploadNewFileName;

                            returrMessage = "Document uploaded successfully.";
                        }
                        else if (documentDetails.UserType == "School")
                        {
                            //Create documents for School
                            documentDetails.DigitalPathofDocument = baseurl + "/Schools";
                            createDir = documentDetails.DigitalPathofDocument + "/" + documentDetails.DocumentType.DocumentTypeName;
                            CreateDirectoryIfNotExists(createDir);
                            filePathTobeSaved     = createDir + "/" + uploadNewFileName;
                            digitalPathofDocument = "~/UploadDocuments/Schools/" + documentDetails.DocumentType.DocumentTypeName + "/" + uploadNewFileName;

                            returrMessage = "Document uploaded successfully.";
                        }
                        Upload(filePathTobeSaved);
                        documentDetails.DigitalPathofDocument = digitalPathofDocument;
                        documentDetails.DocumentSubmission_ID = objDocumentSubmissionViewModel.DocumentSubmission_ID;
                        stringContent = new StringContent(JsonConvert.SerializeObject(documentDetails).ToString(), Encoding.UTF8, "application/json");
                        // var status = Update(stringContent);
                        returrMessage = digitalPathofDocument;
                    }
                    else
                    {
                        returrMessage = "We are unable to process this request due to system down.";
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(returrMessage);
        }