Beispiel #1
0
        public ActionResult UpdateClientInformation(FormCollection fc)
        {
            int id = Convert.ToInt32(fc["RecruitmentId"]);
            RecruitmentService recruitmentService = new RecruitmentService();
            string             hidClientCurrentId = Convert.ToString(fc["hidClientCurrentId"]);

            List <RecruitmentClient>         rcList         = new List <RecruitmentClient>();
            List <RecruitmentClient>         existingRCList = new List <RecruitmentClient>();
            List <RecruitmentClientDocument> rcDocumentList = new List <RecruitmentClientDocument>();

            existingRCList = recruitmentService.GetRecruitmentClientWithId(id);

            recruitmentService.DeleteClientsByRecruitment(id);
            var originalDirectory = Server.MapPath(ConfigurationManager.AppSettings["ClientDocuments"]);
            int rowno             = 0;

            for (int i = 0; i < hidClientCurrentId.Split(',').Length - 1; i++)
            {
                if (!string.IsNullOrEmpty(fc["txtClientName" + (i + 1)]) && !string.IsNullOrEmpty(fc["txtJobTitle" + (i + 1)]) && !string.IsNullOrEmpty(fc["txtCandidateStatus" + (i + 1)]))
                {
                    RecruitmentClient rlvm = new RecruitmentClient();
                    rlvm.JobLocation = Convert.ToString(fc["txtJobLocation" + (i + 1)]);
                    rlvm.JobTitle    = Convert.ToString(fc["txtJobTitle" + (i + 1)]);
                    // rlvm.CandidateStatusList = rvm.CandidateStatusList;
                    rlvm.ClientName = Convert.ToString(fc["txtClientName" + (i + 1)]);
                    //rlvm.Comments = Convert.ToString(fc["txtJobLocation" + (i + 1)]);
                    if (!string.IsNullOrEmpty(fc["txtSubmitionDate" + (i + 1)]))
                    {
                        DateTime dtSubmissionDate = DateTime.MinValue;
                        DateTime.TryParse(fc["txtSubmitionDate" + (i + 1)], out dtSubmissionDate);

                        if (dtSubmissionDate != DateTime.MinValue)
                        {
                            rlvm.SubmissionDate = Convert.ToDateTime(fc["txtSubmitionDate" + (i + 1)]);
                        }
                        else
                        {
                            rlvm.SubmissionDate = null;
                        }
                    }
                    else
                    {
                        rlvm.SubmissionDate = null;
                    }
                    rlvm.LookupCandidateStatus = Convert.ToInt32(fc["txtCandidateStatus" + (i + 1)]);
                    rlvm.RecruitmentId         = id;
                    rlvm.IsActive      = true;
                    rlvm.IsDeleted     = false;
                    rlvm.CreatedDate   = DateTime.Now;
                    rlvm.CreatedUserId = User.Identity.GetUserId();
                    ////rlvm.ClientDocument1 = Convert.ToString(fc["ClientDocument1" + (i + 1)]);
                    //rlvm.ClientDocument2 = Convert.ToString(fc["ClientDocument2" + (i + 1)]);
                    rowno = i + 1;

                    if (Request.Files.Count > 0)
                    {
                        string FileDoc       = string.Format("flClientDoc{0}", (i + 1));
                        string FileDoc2      = string.Format("flClientDoctwo{0}", (i + 1));
                        string oldClientdoc1 = string.Empty;
                        string oldClientdoc2 = string.Empty;
                        if (existingRCList.Count >= rowno)
                        {
                            oldClientdoc1 = existingRCList[i].ClientDocument1;
                            oldClientdoc2 = existingRCList[i].ClientDocument2;
                        }
                        // if (Request.Files.ToString() == FileDoc)
                        //     {
                        HttpPostedFileBase file  = Request.Files[FileDoc];
                        HttpPostedFileBase file1 = Request.Files[FileDoc2];
                        //If Document 1 is null then only upload

                        if (file != null && file.ContentLength > 0)
                        {
                            var    fileName1 = Path.GetFileName(file.FileName);
                            string extension = Path.GetExtension(fileName1);
                            //If no document selected for upload
                            if (!string.IsNullOrEmpty(extension))
                            {
                                string newFileName = Convert.ToString(Guid.NewGuid() + extension);
                                bool   isExists    = System.IO.Directory.Exists(originalDirectory);

                                if (!isExists)
                                {
                                    System.IO.Directory.CreateDirectory(originalDirectory);
                                }

                                var path = string.Format("{0}{1}", originalDirectory, newFileName);
                                file.SaveAs(path);
                                rlvm.ClientDocument1 = newFileName;
                                rlvm.DocumentName1   = fileName1;
                            }
                        }
                        else
                        {
                            if (existingRCList.Count > i)
                            {
                                rlvm.ClientDocument1 = existingRCList[i].ClientDocument1;
                                rlvm.DocumentName1   = existingRCList[i].DocumentName1;
                            }
                        }

                        //    }
                        //else
                        // {
                        //          if (existingRCList.Count > i)
                        //          {
                        //              rlvm.ClientDocument1 = existingRCList[i].ClientDocument1;
                        //              rlvm.ClientDocument2 = existingRCList[i].ClientDocument2;
                        //              rlvm.DocumentName1 = existingRCList[i].DocumentName1;
                        //              rlvm.DocumentName2 = existingRCList[i].DocumentName2;
                        //          }
                        //  }

                        //for File Uploader2
                        //  if (Request.Files.ToString() == FileDoc2)
                        //  {

                        //If Document 2 is null then only upload

                        if (file1 != null && file1.ContentLength > 0)
                        {
                            var    fileName1 = Path.GetFileName(file1.FileName);
                            string extension = Path.GetExtension(fileName1);
                            //If no document selected for upload
                            if (!string.IsNullOrEmpty(extension))
                            {
                                string newFileName = Convert.ToString(Guid.NewGuid() + extension);
                                bool   isExists    = System.IO.Directory.Exists(originalDirectory);

                                if (!isExists)
                                {
                                    System.IO.Directory.CreateDirectory(originalDirectory);
                                }

                                var path = string.Format("{0}{1}", originalDirectory, newFileName);
                                file.SaveAs(path);
                                rlvm.ClientDocument2 = newFileName;
                                rlvm.DocumentName2   = fileName1;
                            }
                        }
                        else
                        {
                            if (existingRCList.Count > i)
                            {
                                rlvm.ClientDocument2 = existingRCList[i].ClientDocument2;
                                rlvm.DocumentName2   = existingRCList[i].DocumentName2;
                            }
                        }
                        //  }
                        //else
                        //{
                        //    if (existingRCList.Count > i)
                        //    {
                        //        rlvm.ClientDocument1 = existingRCList[i].ClientDocument1;
                        //        rlvm.ClientDocument2 = existingRCList[i].ClientDocument2;
                        //        rlvm.DocumentName1 = existingRCList[i].DocumentName1;
                        //        rlvm.DocumentName2 = existingRCList[i].DocumentName2;
                        //    }
                        //}
                    }
                    else
                    {
                        if (existingRCList.Count > i)
                        {
                            rlvm.ClientDocument1 = existingRCList[i].ClientDocument1;
                            rlvm.ClientDocument2 = existingRCList[i].ClientDocument2;
                            rlvm.DocumentName1   = existingRCList[i].DocumentName1;
                            rlvm.DocumentName2   = existingRCList[i].DocumentName2;
                        }
                    }
                    rcList.Add(rlvm);
                }
            }
            rcList = recruitmentService.UpdateClient(rcList);

            return(RedirectToAction("Edit", "Recruitment", new { id = id }));
        }