Beispiel #1
0
        public JsonResult InsertUpdateJobs(Core.Entity.JobEntity model)
        {
            string multipleTraining = string.Empty;

            if (model.multipleTrainings != null && model.multipleTrainings.Count() > 0)
            {
                foreach (var item in model.multipleTrainings)
                {
                    multipleTraining += item + ",";
                }
                model.MultipleTrainingsAssignedCommaSeperated = multipleTraining;
            }

            int Id         = _balService.InsertUpdate(model);
            var jsonResult = Json(Id, JsonRequestBehavior.AllowGet);

            jsonResult.MaxJsonLength = int.MaxValue;
            return(jsonResult);
        }
Beispiel #2
0
        public ActionResult UploadExcel(HttpPostedFileBase FileUpload)
        {
            List <string> data = new List <string>();

            if (FileUpload != null)
            {
                // tdata.ExecuteCommand("truncate table OtherCompanyAssets");

                string filename = FileUpload.FileName;
                if (!Directory.Exists(Server.MapPath("~/Doc/")))
                {
                    // Try to create the directory.
                    DirectoryInfo di = Directory.CreateDirectory(Server.MapPath("~/Doc/"));
                }
                string targetpath = Server.MapPath("~/Doc/");
                FileUpload.SaveAs(targetpath + filename);
                string pathToExcelFile = targetpath + filename;



                DataTable dtable = GetDataTabletFromCSVFile(pathToExcelFile);

                foreach (DataRow dr in dtable.Rows)
                {
                    JobPortal.Core.Entity.JobEntity jobEntity = new Core.Entity.JobEntity();



                    string region = Convert.ToString(dr["Region Name"]);
                    if (!string.IsNullOrEmpty(region))
                    {
                        var regiondetail = _bALRegions.GetRegionByName(region);
                        if (regiondetail != null)
                        {
                            jobEntity.RegionId = regiondetail.Id;
                        }
                    }

                    string training          = Convert.ToString(dr["TrainingName"]);
                    string multipletrainings = string.Empty;
                    foreach (string item in training.Split(','))
                    {
                        if (!string.IsNullOrEmpty(item))
                        {
                            var trainingdetail = _bALTraining.GetTrainingsByName(item);
                            if (trainingdetail != null)
                            {
                                multipletrainings += trainingdetail.ID + ",";
                            }
                        }
                    }



                    jobEntity.MultipleTrainingsAssignedCommaSeperated = multipletrainings.TrimEnd(',');
                    jobEntity.JobTitle       = dr["JobTitle"].ToString();
                    jobEntity.JobDescription = dr["JobDescription"].ToString();
                    jobEntity.JobNumber      = Convert.ToString(dr["JobNumber"]);



                    int Status = 0;
                    switch (Convert.ToString(dr["Status"]).ToLower())
                    {
                    case "open":
                        Status = 1;
                        break;

                    case "in progress":
                        Status = 2;
                        break;

                    case "completed":
                        Status = 3;
                        break;

                    case "close":
                        Status = 4;
                        break;
                    }

                    jobEntity.Status = Status;

                    _balService.InsertUpdate(jobEntity);
                }
                //deleting excel file from folder
                if ((System.IO.File.Exists(pathToExcelFile)))
                {
                    System.IO.File.Delete(pathToExcelFile);
                }
                return(RedirectToAction("index"));
            }
            else
            {
                //alert message for invalid file format
                data.Add("<ul>");
                data.Add("<li>Only Excel file format is allowed</li>");
                data.Add("</ul>");
                data.ToArray();
                return(Json(data, JsonRequestBehavior.AllowGet));
            }
        }