示例#1
0
        public ActionResult UploadDocuments(HttpPostedFileBase file, DocumentInfo documentInfo)
        {
            try
            {
                AuthenticatedUser _authUser;
                string            _fileName = string.Empty;

                using (AuthRepository Repo = new AuthRepository())
                {
                    _authUser = Repo.GetAuthenticatedUserById(CurrentUser.EmployeeInfoId);
                }

                if (_authUser.IsCheckListCompleted == true)
                {
                    return(RedirectToAction("Logout", "Auth", new { area = "" }));
                }

                if (documentInfo.DocumentType != "CV" && documentInfo.DocumentType != "CNICFront" && documentInfo.DocumentType != "CNICBack" && documentInfo.DocumentType != "Other")
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid document type.");

                    return(RedirectToAction("UploadDocuments", "File"));
                }

                if (documentInfo.DocumentType == "Other")
                {
                    if (string.IsNullOrEmpty(documentInfo.FileName))
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Document name is required.");

                        return(RedirectToAction("UploadDocuments", "File"));
                    }

                    _fileName = documentInfo.FileName;
                }

                using (DocumentRepository Repo = new DocumentRepository())
                {
                    var _docList = Repo.GetDocumentListByEmployeeId(CurrentUser.EmployeeInfoId);

                    if (documentInfo.DocumentType == "CV")
                    {
                        _fileName = "CV";

                        int _cvCount = (from x in _docList where x.DocumentType == "CV" select x).ToList().Count();
                        if (_cvCount > 0)
                        {
                            TempData["Msg"] = AlertMessageProvider.FailureMessage("CV has already uploaded.");

                            return(RedirectToAction("UploadDocuments"));
                        }
                    }
                    else if (documentInfo.DocumentType == "CNICFront" || documentInfo.DocumentType == "CNICBack")
                    {
                        _fileName = documentInfo.DocumentType == "CNICFront" ? "CNIC Front" : "CNIC Back";

                        int _cnicCount = (from x in _docList where x.DocumentType == "CNICFront" || x.DocumentType == "CNICBack" select x).ToList().Count();

                        if (_cnicCount == 2)
                        {
                            TempData["Msg"] = AlertMessageProvider.FailureMessage("CNIC has already uploaded.");

                            return(RedirectToAction("UploadDocuments"));
                        }
                    }
                }

                if (file != null)
                {
                    if (file.ContentType.Contains("image") || file.ContentType.Contains("application/pdf"))
                    {
                        if (file.ContentLength < 2 * 1024 * 1024)
                        {
                            if (file.FileName.Contains(".jpeg") || file.FileName.Contains(".jpg") || file.FileName.Contains(".pdf") || file.FileName.Contains("*.pdf"))
                            {
                                documentInfo.FileName       = _fileName + Path.GetExtension(file.FileName);;
                                documentInfo.UploadDate     = DateTime.Now;
                                documentInfo.EmployeeInfoId = CurrentUser.EmployeeInfoId;

                                string _dirPath = Server.MapPath(Url.Content("~/Content/Employee_documents"));

                                bool _isDirectoryExists = System.IO.Directory.Exists(_dirPath);

                                if (!_isDirectoryExists)
                                {
                                    System.IO.Directory.CreateDirectory(Server.MapPath(Url.Content("~/Content/Employee_documents")));
                                }

                                Guid guid = Guid.NewGuid();
                                documentInfo.DocumentPath = Url.Content("~/Content/Employee_documents/" + documentInfo.EmployeeInfoId + "-" + guid + "-" + documentInfo.FileName);
                                string _docPath = Server.MapPath(documentInfo.DocumentPath);

                                using (var transaction = new System.Transactions.TransactionScope())
                                {
                                    file.SaveAs(_docPath);

                                    var _documentList = new List <DocumentInfo>();

                                    using (DocumentRepository Repo = new DocumentRepository())
                                    {
                                        Repo.SaveDocument(documentInfo);

                                        _documentList = Repo.GetRequiredDocumentListByEmployeeId(CurrentUser.EmployeeInfoId);
                                    }

                                    if (_documentList.Count() >= 3)
                                    {
                                        using (AccountCheckListRepository Repo = new AccountCheckListRepository())
                                        {
                                            AccountCheckListInfo accountCheckListInfo = new AccountCheckListInfo();

                                            accountCheckListInfo.IsDocumentsUploaded = true;
                                            accountCheckListInfo.AccountId           = CurrentUser.AccountId;

                                            Repo.UpdateIsDocumentsUploaded(accountCheckListInfo);
                                        }
                                    }

                                    transaction.Complete();
                                }
                            }
                            else
                            {
                                TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select jpeg, jpg, pdf format only.");

                                return(RedirectToAction("UploadDocuments", "File"));
                            }
                        }
                        else
                        {
                            TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select size upto 2 MB or smaller.");

                            return(RedirectToAction("UploadDocuments", "File"));
                        }
                    }
                    else
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid content type, please select image and pdf only.");

                        return(RedirectToAction("UploadDocuments", "File"));
                    }
                }
                else
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select document.");

                    return(RedirectToAction("UploadDocuments", "File"));
                }

                TempData["Msg"] = AlertMessageProvider.SuccessMessage("Document uploaded successfully.");

                return(RedirectToAction("UploadDocuments", "File"));
            }

            catch (Exception ex)
            {
                TempData["Msg"] = AlertMessageProvider.FailureMessage(ex.ToString());

                return(View());
            }
        }
示例#2
0
        // GET: EmployeeReg/File/UploadDocuments
        public ActionResult UploadDocuments()
        {
            try
            {
                AuthenticatedUser _authUser;
                var _registration = new RegistrationViewModel();

                using (AuthRepository Repo = new AuthRepository())
                {
                    _authUser = Repo.GetAuthenticatedUserById(CurrentUser.EmployeeInfoId);
                }

                if (_authUser.IsCheckListCompleted == true)
                {
                    return(RedirectToAction("Logout", "Auth", new { area = "" }));
                }

                using (EmployeeRepository Repo = new EmployeeRepository())
                {
                    _registration.employeeRegistrationInfo = Repo.GetRegisterEmployeeInfoById(CurrentUser.EmployeeInfoId);
                }

                using (DocumentRepository Repo = new DocumentRepository())
                {
                    _registration.documentInfoList = Repo.GetDocumentListByEmployeeId(CurrentUser.EmployeeInfoId);
                }

                using (AccountCheckListRepository Repo = new AccountCheckListRepository())
                {
                    _registration.accountCheckListInfo = Repo.GetAccountCheckListByUserId(CurrentUser.AccountId);

                    if (_registration.accountCheckListInfo.IsPersonalInfoProvided == false)
                    {
                        return(RedirectToAction("PersonalInfo", "Profile"));
                    }

                    if (_registration.employeeRegistrationInfo.MaritalStatus == "Married")
                    {
                        using (FamilyMemberRepository FamilyRepo = new FamilyMemberRepository())
                        {
                            _registration.familyMembersList = FamilyRepo.GetFamilyMembersListByEmployeeId(CurrentUser.EmployeeInfoId);

                            if (_registration.familyMembersList.Count() <= 0)
                            {
                                return(RedirectToAction("Details", "Family"));
                            }
                        }
                    }

                    int count = (from x in _registration.documentInfoList where x.DocumentType == "CNICFront" || x.DocumentType == "CNICBack" || x.DocumentType == "CV" select x).ToList().Count();

                    if (count < 3)
                    {
                        var _accountCheckList = new AccountCheckListInfo();

                        _accountCheckList.IsDocumentsUploaded = false;
                        _accountCheckList.AccountId           = CurrentUser.AccountId;

                        Repo.UpdateIsDocumentsUploaded(_accountCheckList);
                        _registration.accountCheckListInfo = Repo.GetAccountCheckListByUserId(CurrentUser.AccountId);
                    }
                }

                return(View(_registration));
            }

            catch (Exception ex)
            {
                TempData["Msg"] = AlertMessageProvider.FailureMessage(ex.ToString());

                return(View());
            }
        }