public HttpResponseMessage UpdateProjectSite(ProjectSites wo) { PM_ProjectSitesBL ub = new PM_ProjectSitesBL(); Response res = new Response(); try { if (wo.ProjectSiteId > 0) { bool result = ub.Update("Update", wo, wo.UserId); if (result) { return(this.Request.CreateResponse(HttpStatusCode.OK, new { Message = "Project Site Updated", Value = 1 })); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Project Site Not Updated ")); } } } catch (Exception ex) { res.Status = "danger"; res.Message = ex.Message; } return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Error to save data")); }
public ActionResult Edit(ProjectSites wo, bool?ControlledIntro, bool?VMME, bool?SuperBowl) { try { ub.Update("Update", wo, Convert.ToInt64(ViewBag.UserId)); } catch (Exception ex) { TempData["message"] = "error"; return(View()); } string ProjectId = TempData["ProjectId"] as string; TempData.Keep("ProjectId"); TempData["message"] = "success"; // TempData["msg_success"] = "success"; //return RedirectToAction("All", new { Id = ProjectId }); return(RedirectToAction("Edit", new { Id = wo.ProjectId, ProjectSiteId = wo.ProjectSiteId })); }
public bool Update(string filter, ProjectSites wo, long?UserId) { try { dbDataTable ddt = new dbDataTable(); //DataTable dt = ddt.List(); // myDataTable.AddRow(dt, "Value1", wo.ProjectId, "Value2", wo.SiteCode, "Value3", wo.ReceivedOn, "Value4", wo.SiteTypeId, "Value5", wo.ClusterCode, // "Value6", wo.Market, "Value7", wo.Color, "Value8", wo.Scope, "Value9", wo.SiteName, "Value10", wo.SiteClassId, "Value11", wo.siteLatitude, //"Value12", wo.siteLongitude, "Value13", wo.Description, "Value14", wo.SiteAddress, "Value15", wo.Client); DataTable dt = ddt.ListProjectSites(); myDataTable.AddRow(dt, "WoRefId", null, "ProjectId", wo.ProjectId, "SiteCode", wo.SiteCode, "SiteName", wo.SiteName, "SiteDate", null, "SiteTypeId", wo.SiteTypeId, "SiteClassId", wo.SiteClassId, "Latitude", wo.siteLatitude, "Longitude", wo.siteLongitude, "RevisionId", null, "PMCode", null, "PMRefId", null, "ClusterId", null, "ClusterCode", wo.ClusterCode, "CityId", wo.Market, "StatusId", null, "MSWindowId", null, "PriorityId", null, "ColorId", wo.Color, "CreatedOn", null, "CreatedBy", null, "IsActive", null, "BudgetCost", null, "ActualCost", null, "Description", wo.Description, "ClientId", wo.Client, "ScopeId", wo.Scope, "ReceivedOn", wo.ReceivedOn, "Address", wo.SiteAddress, "PlannedDate", null, "TargetDate", null, "ActualStartDate", null, "ActualEndDate", null, "EstimatedStartDate", null, "EstimatedEndDate", null, "MilestoneId", null, "StageId", null, "FACode", wo.SiteCode, "USID", wo.USID, "CommonId", null, "MarketId", wo.Market, "SubMarketId", null, "CountyId", null, "vMME", wo.vMME, "ControlledIntro", wo.ControlledIntro, "SuperBowl", wo.SuperBowl, "isDASInBuild", wo.isDASInBuild, "FirstNetRAN", wo.FirstNetRAN, "IPlanJob", wo.IPlanJob, "PaceNo", wo.PaceNo, "IPlanIssueDate", wo.IPlanIssueDate, "SubMarket", wo.SubMarket, "County", null, "AlarmId", null, "Value1", null, "Value2", null, "Value3", null, "Value4", null, "Value5", null, "Value6", null, "Value7", null, "Value8", null, "Value9", null, "Value10", null); wod.Manage(filter, dt, UserId, wo.ProjectSiteId); return(true); } catch (Exception ex) { throw; } }
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)); }