public JsonResult GetSitesTask(Int64 ProjectSiteId) { PM_ProjectBL bl = new PM_ProjectBL(); var Tasks = bl.GetTasks("ProjectSiteTasks", ProjectSiteId).Select(p => new { TaskId = p.TaskId, Title = p.Title }).ToList(); return(Json(Tasks, JsonRequestBehavior.AllowGet)); }
public JsonResult ToSingle(string Filter, string Value) { PM_ProjectBL pd = new PM_ProjectBL(); PM_GazetteHolidaysBL gh = new PM_GazetteHolidaysBL(); PM_TaskStagesBL pM_TaskStagesBL = new PM_TaskStagesBL(); var rec = pd.ToSingle(Filter, Value); if (Value != "0") { var ghh = gh.ToList("ByProjectId", Value); if (ghh.Count > 0) { rec.GH = ghh; } var obj = pM_TaskStagesBL?.ToList("GetByProjectId", long.Parse(Value)); if (obj.Count > 0) { rec.TS = obj; } } // rec.TS = pM_TaskStagesBL?.ToList("GetByProjectId", long.Parse(Value)); return(Json(rec, JsonRequestBehavior.AllowGet)); }
public JsonResult GetSitesList(Int64 ProjectId) { PM_ProjectBL bl = new PM_ProjectBL(); var Sites = bl.Get("ProjectSitesByProjectId", ProjectId).Select(p => new { SiteName = p.SiteName, SiteId = p.ProjectSiteId }).ToList(); return(Json(Sites, JsonRequestBehavior.AllowGet)); }
public HttpResponseMessage GetProjectLookUp(object Json) { try { PM_ProjectBL pd = new PM_ProjectBL(); PM_ProjectLookup rec = new PM_ProjectLookup(); ProjectApiObject obj = JsonConvert.DeserializeObject <ProjectApiObject>(Json.ToString()); if (obj.toDate != null && obj.fromDate != null) { rec = pd.GetLookup("LookupByFilters", "True", obj.userId, obj.statusIds, obj.priorityIds, obj.clientIds, obj.toDate, obj.fromDate); } else if (obj.searchKey != null && obj.searchKey != "") { rec = pd.GetLookup("LookupByKey", obj.searchKey, obj.userId); } else { rec = pd.GetLookup("Lookup", "True", obj.userId); } if (rec != null) { return(Request.CreateResponse(HttpStatusCode.OK, rec)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No Data")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
public HttpResponseMessage ToList(string _filter = "", bool _active = true, Int64 _userId = 0) { PM_ProjectBL pd = new PM_ProjectBL(); var rec = pd.ToList(_filter, Convert.ToString(_active), _userId); if (rec != null) { return(Request.CreateResponse(HttpStatusCode.OK, rec)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No Data")); } }
public JsonResult Details(Int64 Id, string Key) { PM_ProjectBL pd = new PM_ProjectBL(); var Project = pd.ToSingle("ByProjectId", Id.ToString()); AD_DefinationBL db = new AD_DefinationBL(); var ProjectStatus = db.ToList("byDefinationType", "Project Status"); Int64 UserId = ViewBag.UserId; var UserScopes = db.ToList("UserScopes", UserId.ToString()); var Priorities = db.ToList("byDefinationType", "Priority"); var FormTypes = db.ToList("byDefinationType", "FormType"); var TaskTypes = db.ToList("byDefinationType", "Task Types"); Sec_UserBL ud = new Sec_UserBL(); List <Sec_User> Users = ud.ToList("ByProjectId", Id.ToString()); Users = Users.Select(c => { c.Password = ""; return(c); }).ToList(); return(Json(new { Project = Project, ProjectStatus = ProjectStatus, UserScopes = UserScopes , Priorities = Priorities, FormTypes = FormTypes, Users = Users, TaskTypes = TaskTypes }, JsonRequestBehavior.AllowGet)); }
public JsonResult ToList(string Filter, string Value) { PM_ProjectBL pd = new PM_ProjectBL(); var User = Session["user"] as LoginInformation; var rec = pd.ToList(Filter, true.ToString(), User.UserId); if (Filter == "ByStatus") { List <Sec_UserProjects> lst = new List <Sec_UserProjects>(); var items = rec.Where(l2 => !User.ProjectPermissions.Any(l1 => l1.ProjectId == l2.ProjectId)).ToList(); if (items.Count > 0) { foreach (var item in items) { Permission.AddProject(item.ProjectId); } } } return(Json(rec, JsonRequestBehavior.AllowGet)); }
public ActionResult PlanProject(string Filter, Int64 ProjectId = 0, Int64 RevisionId = 0, DateTime?FromDate = null, DateTime?ToDate = null, string LocationIds = null, string TaskIds = null, string SiteStatus = null, Int64 UserId = 0) { PM_ProjectBL pal = new PM_ProjectBL(); AD_DefinationBL dbl = new AD_DefinationBL(); Sec_UserBL ud = new Sec_UserBL(); List <PM_ProjectSite> result = pal.PM_PlanProject(Filter, ProjectId, RevisionId, FromDate, ToDate, LocationIds, TaskIds, SiteStatus, UserId); List <SelectedList> listStatus = dbl.SelectedList("byDefinationType", "Project Status"); ViewBag.StatusId = listStatus; List <SelectedList> listUsers = ud.SelectedList("ByProjectId", ProjectId.ToString()); List <PM_CompanyHierarchy> lstCompUsers = ListCompanyUsers("ByProjectId", ProjectId.ToString()); List <Client> listOfClient = lstCompUsers.GroupBy(xx => xx.ClientId).Select(x => new Client() { ClientId = x.Key, ClientName = lstCompUsers.Where(XVC => XVC.ClientId == x.Key).FirstOrDefault().ClientName, userRolesList = lstCompUsers.Where(xr => xr.ClientId == x.Key).GroupBy(zx => zx.RoleId).Select(urol => new UserRoles() { RoleId = urol.Key, RoleName = lstCompUsers.FirstOrDefault(zzzz => zzzz.RoleId == urol.Key).RoleName, userList = lstCompUsers.Where(zzzz1 => zzzz1.RoleId == urol.Key && zzzz1.ClientId == x.Key).Select(usr => new Users() { FirstName = usr.FirstName, LastName = usr.LastName, UserId = usr.UserId, UserName = usr.UserName }).ToList() }).ToList() }).ToList(); foreach (var item in result) { item.SelectedListStatus = listStatus; item.Clients = listOfClient; //item.ActualEndDate = item.ActualStartDate!=null? Convert.ToDateTime(item.ActualStartDate).ToShortDateString():null; } return(PartialView("~/Areas/Project/Views/Task/_PlanProject.cshtml", result)); }
public ActionResult New(PM_Project p) { Response res = new Response(); AL_AlertBL model = new AL_AlertBL(); try { // Insert Project Status Change Notification - Start AL_GetAlertSubscription Temp = new AL_GetAlertSubscription(); Temp = model.IsSubscribed("IsSubscribed", (int)ViewBag.UserId, 0, (int)p.ProjectId, "Project Status Change"); if (Temp.IsSubscribed) { int status = model.InsertAlert("Insert_Alert", (int)p.ProjectId, (int)ViewBag.UserId, 0, (int)p.ProjectId, "Project Status Change", (int)p.StatusId); } // Insert Project Status Change Notification - End int x = 0; PM_ProjectBL pb = new PM_ProjectBL(); PM_GazetteHolidaysBL gh = new PM_GazetteHolidaysBL(); PM_WorkGroupsBL PWG = new PM_WorkGroupsBL(); PM_TaskStagesBL pM_TaskStagesBL = new PM_TaskStagesBL(); if (p.WorkingDays != null) { p.WorkingDays = p.WorkingDays.Substring(0, p.WorkingDays.Length - 1); } if (p.ProjectId > 0) { pb.Manage("Update", p); Int64 UID = ViewBag.UserId; pb.ProjectUserPermission("UpdateUserPermissions", p.ManagerId, p.ProjectId); //pb.ProjectUserPermission("UpdateUserPermissions", UID, p.ProjectId); Permission.UpdateEntity(ViewBag.UserId); PWG.Manage("Insert", p.ProjectId, p.WorkGroups); if (p.GH != null) { p.GH[0].ProjectId = p.ProjectId; gh.Manage("Delete", p.GH[0]); gh.InsertBulk(p.ProjectId, p.GH); } else { PM_GazetteHolidays g = new PM_GazetteHolidays(); g.ProjectId = p.ProjectId; g.Date = DateTime.Now; gh.Manage("Delete", g); pb.ProjectUserPermission("UpdateUserPermissions", p.ManagerId, p.ProjectId); //pb.ProjectUserPermission("UpdateUserPermissions", UID, p.ProjectId); Permission.UpdateEntity(ViewBag.UserId); } // Update AND Add Task Stages if (p.TS?.Count > 0) { bool IsEXE = pM_TaskStagesBL.UpdateOrAdd("UpdateOrAdd", p.ProjectId, p.TS); } res.Message = "Update successfully"; } else { p.IsActive = true; var PId = pb.Manage("Insert", p); PWG.Manage("Insert", PId, p.WorkGroups); Int64 UID = ViewBag.UserId; pb.ProjectUserPermission("InsertUserPermissions", p.ManagerId, PId); pb.ProjectUserPermission("InsertUserPermissions", UID, PId); Permission.UpdateEntity(ViewBag.UserId); if (p.GH != null) { gh.InsertBulk(PId, p.GH); } if (p?.TS?.Count > 0) { var IsInserted = pM_TaskStagesBL.InsertBulk(PId, p.TS); } res.Value = PId; Permission.AddProject(PId); res.Message = "Save successfully"; } res.Status = "success"; } catch (Exception ex) { res.Status = "danger"; if (ex.Message == "Object cannot be cast from DBNull to other types.") { res.Message = "You Can't Insert Project who is already entered with same name and same client "; } else { res.Message = ex.Message; } } return(Json(res, JsonRequestBehavior.AllowGet)); }
public ActionResult UploadSites(string id) { var oob = Permission.AllowProject(Convert.ToInt64(id)); if (oob == null) { TempData["msg_error"] = "This Project is not assigned to you. Please contact administrator for project assignment."; return(RedirectToAction("index", "error", new { Area = "Project" })); } else { TempData["ProjectEntity"] = oob; TempData.Keep("ProjectEntity"); } Response response = new Response(); response.Status = "Unsuccessfull"; response.Message = "Site(s) not Imported. Please try again!"; try { AD_DefinationBL defination = new AD_DefinationBL(); Sec_UserSettingsDL usrSetting = new Sec_UserSettingsDL(); DataTable Table = usrSetting.GetDataTable("UserProjects", Convert.ToString(ViewBag.UserId), null, null); var ProjectsList = Table.ToList <PM_Projects>().Where(x => x.ProjectId == long.Parse(id)).ToList(); bool isProjectNotEExist = false; List <string> ErrorFile = new List <string>(); PM_ProjectBL projectBL = new PM_ProjectBL(); var ProjectFACodeList = projectBL.ProjectFACode("ProjectFACodeList", Convert.ToInt64(id)); SWI.AirView.Common.SelectedList sl = new SWI.AirView.Common.SelectedList(); string FileNamePrefix = DateTime.Now.ToString("Error_File_ddMMhhmmss_"); string FileName = null; bool IsFileExist = false; string[] DataInTable = null; string path = null; Int64 ProjectIdOut = 0; if (isProjectNotEExist) { Table = usrSetting.GetDataTable("UserProjects", Convert.ToString(ViewBag.UserId), null, null); ProjectsList = Table.ToList <PM_Projects>().Where(x => x.ProjectId == long.Parse(id)).ToList(); } if (string.IsNullOrEmpty(id) || string.IsNullOrWhiteSpace(id)) { response.Status = "InvalidProjectID"; response.Message = "Project ID is Empty. Please close the tab and reopen it."; return(Json(response)); } else { if (!Int64.TryParse(id, out ProjectIdOut)) { response.Status = "InvalidProjectID"; response.Message = "Project ID is Invalid. Please close the tab and reopen it."; return(Json(response)); } } if (ProjectsList?.Count <= 0) { response.Status = "ProjectPermissionIssue"; response.Message = "Sorry, You don't have permission for this Project."; return(Json(response)); } for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; var fileName = Path.GetFileName(file.FileName); FileName = FileNamePrefix + fileName; path = Path.Combine(Server.MapPath("~/files/Raw"), FileName); if (Path.GetExtension(path) != ".csv") { response.Status = "Unsuccessfull"; response.Message = "Invalid file format, Only CSV file supported."; return(Json(response)); } file.SaveAs(path); IsFileExist = true; } if (IsFileExist) { List <SelectListItem> Scopes = sl.Definations("UserScopes", Convert.ToString(ViewBag.UserId)); var SiteTypes = sl.Definations("SiteTypes"); List <SWI.Libraries.AD.Entities.AD_Defination> Cities = defination.ToList("UserCities", Convert.ToString(ViewBag.UserId)); DataInTable = System.IO.File.ReadAllLines(path); List <ProjectSites> Sites = new List <ProjectSites>(); string FileHeader = string.Empty; if (DataInTable?.Count() == 1) { response.Status = "EmptyFile"; response.Message = "File is empty!"; return(Json(response)); } if (DataInTable?.Count() > 0) { FileHeader = string.Join(",", DataInTable[0].Split(',').Take(20).ToArray()) + ",Error(s)"; } ErrorFile.Add(FileHeader); string InValidInput = string.Empty; string RequiredFileds = string.Empty; string InvalidLength = string.Empty; string InvalidDataType = string.Empty; string FACodeAlreadyExist = string.Empty; List <string> FACodeInFile = new List <string>(); foreach (var item in DataInTable.Skip(1)) { var cols = item.Split(','); if (cols?.Count() > 0) { FACodeInFile.Add(cols[3]); } } foreach (var row in DataInTable.Skip(1)) { InValidInput = string.Empty; RequiredFileds = string.Empty; InvalidLength = string.Empty; InvalidDataType = string.Empty; FACodeAlreadyExist = string.Empty; ProjectSites site = new ProjectSites(); site.ProjectId = Convert.ToInt64(id); var Cols = row.Split(','); if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 0)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 0))) { var Market = Cities?.FirstOrDefault(x => x.DefinationName.ToLower() == Cols[0].ToLower()); if (Market != null) { site.Market = Convert.ToString(Market.DefinationId); } else { InValidInput += "[Market]"; } } else { RequiredFileds += "[Market]"; } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 1)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 1))) { var Scope = Scopes?.FirstOrDefault(x => x.Text.ToLower() == Cols[1].ToLower()); if (Scope != null) { site.Scope = Convert.ToString(Scope.Value); } else { InValidInput += "[Scope]"; } } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 2)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 2))) { if (Cols[2].Length > 50) { InvalidLength += "[Cluster Code > 50]"; } else { site.ClusterCode = Cols[2]; site.clusterId = Cols[2]; } } else { RequiredFileds += "[Cluster Code]"; } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 3)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 3))) { if (Cols[3].Length > 25) { InvalidLength += "[Site Code > 25]"; } else { var IsFACodeExist = ProjectFACodeList?.Where(x => x.FACode.Trim().ToLower() == Cols[3].Trim().ToLower())?.Count() > 0 ? true : false; bool IsFACodeExistInFile = FACodeInFile?.Where(x => x.Trim().ToLower() == Cols[3].Trim().ToLower())?.Count() > 1 ? true : false; if (IsFACodeExist == false && IsFACodeExistInFile == false) { site.SiteCode = Cols[3]; site.FACode = Cols[3]; } else { FACodeAlreadyExist += "[Site Code]"; } } } else { RequiredFileds += "[Site Code]"; } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 4)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 4))) { if (Cols[4].Length > 500) { InvalidLength += "[Site Name > 500]"; } else { site.SiteName = Cols[4]; } } else { RequiredFileds += "[Site Name]"; } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 5)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 5))) { double Out = 0; if (!double.TryParse(Cols[5], out Out)) { InvalidDataType += "[Latitude]"; } if (Cols[5].Length > 500) { InvalidLength += "[Latitude > 500]"; } else { site.siteLatitude = Cols[5]; } } else { RequiredFileds += "[Latitude]"; } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 6)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 6))) { double Out = 0; if (!double.TryParse(Cols[6], out Out)) { InvalidDataType += "[Longitude]"; } if (Cols[6].Length > 500) { InvalidLength += "[Longitude > 500]"; } else { site.siteLongitude = Cols[6]; } } else { RequiredFileds += "[Longitude]"; } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 7)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 7))) { var siteTypes = SiteTypes?.FirstOrDefault(x => x.Text.ToLower() == Cols[7].ToLower()); if (siteTypes != null) { site.SiteTypeId = Convert.ToString(siteTypes.Value); } else { InValidInput += "[Site Type]"; } } else { RequiredFileds += "[Site Type]"; } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 8)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 8))) { if (Cols[8].Length > 7) { InvalidLength += "[Color > 7]"; } else { site.Color = Cols[8]; } } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 9)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 9))) { if (Cols[9].Length > 500) { InvalidLength += "[Description > 500]"; } else { site.Description = Cols[9]; } } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 10)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 10))) { if (Cols[10].Length > 25) { InvalidLength += "[USID > 25]"; } else { site.USID = Cols[10]; } } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 11)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 11))) { if (Cols[11].Length > 150) { InvalidLength += "[Sub Market > 150]"; } else { site.SubMarket = Cols[11]; } } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 12)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 12))) { bool Out = false; if (!bool.TryParse(Cols[12], out Out)) { InvalidDataType += "[vMME]"; } else { site.vMME = Convert.ToBoolean(Cols[12]); } } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 13)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 13))) { bool Out = false; if (!bool.TryParse(Cols[13], out Out)) { InvalidDataType += "[Controlled Intro]"; } else { site.ControlledIntro = Convert.ToBoolean(Cols[13]); } } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 14)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 14))) { bool Out = false; if (!bool.TryParse(Cols[14], out Out)) { InvalidDataType += "[Super Bowl]"; } else { site.SuperBowl = Convert.ToBoolean(Cols[14]); } } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 15)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 15))) { if (Cols[15].Length > 50) { InvalidLength += "[isDASInBuild > 50]"; } else { site.isDASInBuild = Convert.ToString(Cols[15]); } } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 16)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 16))) { if (Cols[16].Length > 50) { InvalidLength += "[FirstNetRAN > 50]"; } else { site.FirstNetRAN = Convert.ToString(Cols[16]); } } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 17)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 17))) { if (Cols[17].Length > 50) { InvalidLength += "[IPlan Job > 50]"; } else { site.IPlanJob = Convert.ToString(Cols[17]); } } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 18)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 18))) { if (Cols[18].Length > 50) { InvalidLength += "[PaceNo > 50]"; } else { site.PaceNo = Convert.ToString(Cols[18]); } } if (!string.IsNullOrEmpty(Utilities.ElementAtOrDefault(Cols, 19)) && !string.IsNullOrWhiteSpace(Utilities.ElementAtOrDefault(Cols, 19))) { DateTime Out = DateTime.Now; if (!DateTime.TryParse(Cols[19], out Out)) { InvalidDataType += "[Invalid IPlanIssueDate]"; } if (Cols[19].Length > 10) { InvalidLength += "[IPlanIssueDate > 10]"; } else { site.IPlanIssueDate = Convert.ToString(Cols[19]); } } if (string.IsNullOrEmpty(RequiredFileds) && string.IsNullOrEmpty(InValidInput) && string.IsNullOrEmpty(InvalidDataType) && string.IsNullOrEmpty(InvalidLength) && string.IsNullOrEmpty(FACodeAlreadyExist)) { Sites.Add(site); } else { if (!string.IsNullOrEmpty(RequiredFileds)) { RequiredFileds += (RequiredFileds?.TrimEnd(',')?.Split(',')?.Count() >= 2) ? " are required." : " is required."; } if (!string.IsNullOrEmpty(InvalidLength)) { InvalidLength += " has Invalid Length."; } if (!string.IsNullOrEmpty(InvalidDataType)) { InvalidDataType += " have invalid data type."; } if (!string.IsNullOrEmpty(InValidInput)) { InValidInput += " have invalid input."; } if (!string.IsNullOrEmpty(FACodeAlreadyExist)) { FACodeAlreadyExist += " already exist."; } string NewRowWithErrors = $"{string.Join(",", Cols.Take(20).ToArray()).TrimEnd(',')},{RequiredFileds} {FACodeAlreadyExist} {InValidInput} {InvalidDataType} {InvalidLength} "; ErrorFile.Add(NewRowWithErrors); } } if (Sites?.Count > 0 && ErrorFile.Count <= 1) { var IsInserted = ub.Insert("Insert", Sites, Convert.ToInt64(ViewBag.UserId), 0, Sites[0].SiteName); if (IsInserted) { response.Status = "Ok"; response.Message = "Site(s) imported successfully!"; } else { response.Status = "Unsuccessfull"; response.Message = "There is an unexpected error. Please try again!"; } } else if (ErrorFile.Count > 1) { System.IO.File.WriteAllLines(Path.Combine(Server.MapPath("~/files/Raw"), FileName), ErrorFile); response.Status = "OkWithErrorFile"; response.Value = $"/files/Raw/{FileName}"; response.Message = "File could not be uploaded due to errors in file."; } else { response.Status = "Unsuccessfull"; response.Message = "There is an unexpected error. Please try again!"; } } } catch (Exception e) { return(Json(response)); } return(Json(response)); }
public ActionResult FileUpload(HttpPostedFileBase Upload) { dbDataTable ddt = new dbDataTable(); DataTable FileRecord = ddt.Tb_PM_Target(); PM_TargetsBL tb = new PM_TargetsBL(); PM_ProjectBL P = new PM_ProjectBL(); PM_TaskBL ttb = new PM_TaskBL(); dbDataTable dbdt = new dbDataTable(); TempData.Keep("ProjectId"); string ProjectId = TempData["ProjectId"] as string; try { if (Upload != null && Upload.ContentLength > 0) { if (Upload.FileName.EndsWith(".csv") || Upload.FileName.EndsWith(".CSV")) { Stream stream = Upload.InputStream; using (CsvReader csvReader = new CsvReader(new StreamReader(stream), true)) { FileRecord.Load(csvReader); } List <PM_Target_File> target = FileRecord.ToList <PM_Target_File>(); var dtt = ttb.ToList("Get_Project_Tasks", string.Empty, string.Empty, Convert.ToInt64(ProjectId), 0).ToArray(); string ProjectName = P.ToList("ByProjectId", ProjectId, 0).Select(x => x.ProjectName).FirstOrDefault(); var id = Session["user"]; var userId = (LoginInformation)id; DataTable dt = dbdt.List(); foreach (var tr in target) { if (tr.Project == ProjectName) { var results = Array.FindAll(dtt, s => s.Title.Equals(tr.Task)).FirstOrDefault(); if (results != null) { if (tr.TargetType.ToLower() == "day") { myDataTable.AddRow(dt, "Value1", ProjectId, "Value2", results.TaskId, "Value3", null, "Value4", tr.TargetType, "Value5", tr.TargetValue, "Value6", null, "Value7", tr.SiteCount, "Value8", userId.UserId.ToString()); } else { myDataTable.AddRow(dt, "Value1", ProjectId, "Value2", results.TaskId, "Value3", null, "Value4", tr.TargetType, "Value5", null, "Value6", tr.TargetValue, "Value7", tr.SiteCount, "Value8", userId.UserId.ToString()); } } } } if (tb.Manage("Insert", "", dt)) { TempData["msg_success"] = "Save successfully."; } else { TempData["msg_nothing"] = "No row effect"; } } else { TempData["msg_error"] = "Select .csv File"; } } else { TempData["msg_error"] = "No file selected"; } } catch (Exception ex) { TempData["msg_error"] = ex.Message; } return(RedirectToAction("Index", new { @id = Convert.ToInt64(ProjectId) })); }