public HttpResponseMessage Edit(int id, string SiteName) { List <LocationIndicatorViewModel> lstLocationIndicatorViewModel = new List <LocationIndicatorViewModel>(); LocationIndicatorViewModel objLocationIndicatorViewModel = new LocationIndicatorViewModel(); objLocationIndicatorViewModel.SiteName = SiteName; objLocationIndicatorViewModel.AreaOfInterestId = id; using (ThomsonDbContext db = new ThomsonDbContext(SiteName)) { objLocationIndicatorViewModel.Name = db.InterestLocation.First(m => m.AreaOfInterestId == id).Name; objLocationIndicatorViewModel.LoctionIndicatorId = db.LocationIndicator.First(m => m.AreaOfInterestId == id).LoctionIndicatorId; foreach (var item in db.LocationIndicator.Where(m => m.AreaOfInterestId == id)) { MapLocation objMapLocation = new MapLocation(); objMapLocation.LoctionIndicatorId = item.LoctionIndicatorId; objMapLocation.LoctionIndicator = item.LoctionIndicator; objMapLocation.AreaOfInterestId = item.AreaOfInterestId; objLocationIndicatorViewModel.lstMapLocations.Add(objMapLocation); } foreach (var item in db.NeighBourAreas.Where(m => m.AreaId == id)) { NeighBourAreaMap objNeighBourMapLocation = new NeighBourAreaMap(); objNeighBourMapLocation.NeighBourId = item.NeighbourAreaId; objNeighBourMapLocation.NeighBourName = item.AreaCode.ToString(); objNeighBourMapLocation.AreaOfInterestId = item.AreaId; objLocationIndicatorViewModel.lstNeighBourMaps.Add(objNeighBourMapLocation); } } lstLocationIndicatorViewModel.Add(objLocationIndicatorViewModel); return(Request.CreateResponse(objLocationIndicatorViewModel)); }
public HttpResponseMessage ClearFileData(string lstDataFileIds, string ConnectionString) { DataFileImporter objDataFileImporter = new DataFileImporter(); try { string connectionstring = Regex.Replace(ConnectionString.Trim(), @"\t|\n|\r", ""); using (ThomsonDbContext db = new ThomsonDbContext(ConnectionString)) { foreach (var item in lstDataFileIds.Split(',')) { int idItem = Convert.ToInt32(item); DataFile objdataFile = db.DataFiles.Find(idItem); db.DataFiles.Remove(objdataFile); db.SaveChanges(); retMessage = "successfully Deleted"; } } } catch (Exception ex) { retMessage = ex.InnerException.Message; throw ex; } return(new HttpResponseMessage() { Content = new StringContent(retMessage) }); }
public HttpResponseMessage GetDataFromSmtp(string lstDataFileIds, string ConnectionString) { DataFileImporter objDataFileImporter = new DataFileImporter(); try { string connectionstring = Regex.Replace(ConnectionString.Trim(), @"\t|\n|\r", ""); using (ThomsonDbContext db = new ThomsonDbContext(ConnectionString)) { foreach (var item in lstDataFileIds.Split(',')) { int idItem = Convert.ToInt32(item); string pathName = db.DataFiles.Where(m => m.Id == idItem).FirstOrDefault().FileName; string fileName = Path.GetFileName(pathName); objDataFileImporter.SaveDataFile(pathName, fileName, ConnectionString); retMessage = "successfully Saved"; } } } catch (Exception ex) { retMessage = ex.InnerException.Message; throw ex; } return(new HttpResponseMessage() { Content = new StringContent(retMessage) }); }
public HttpResponseMessage LoadSftpData(string strDateFormat, string ConnectionString) { try { DataFileImporter objDataFileImporter = new DataFileImporter(); List <DataFile> lstDataFile = new List <DataFile>(); ConnectionString = Regex.Replace(ConnectionString.Trim(), @"\t|\n|\r", ""); using (ThomsonDbContext db = new ThomsonDbContext(ConnectionString)) { Session session = new Session(); string path = db.Parameters.FirstOrDefault(m => m.Name == "RemotePath").Value; string localFolder = System.Web.Hosting.HostingEnvironment.MapPath("~/ZipCsvs"); SessionOptions sessionOptions = new SessionOptions { Protocol = Protocol.Sftp, HostName = ConfigurationManager.AppSettings["HostName"], UserName = ConfigurationManager.AppSettings["UserName"], Password = ConfigurationManager.AppSettings["Password"], }; sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = true; session.Open(sessionOptions); string remoteFilePath = db.Parameters.FirstOrDefault(m => m.Name == "RemotePath").Value + "/" + strDateFormat + "/" + "cleaned"; if (session.FileExists(remoteFilePath)) { //Fetch all the Files from SFTP as per configuration structure setting in Config var SftpFiles = session.EnumerateRemoteFiles(remoteFilePath, "", EnumerationOptions.None).Where(m => m.Name.Contains(ConfigurationManager.AppSettings["csvFileNameFormat1"].ToString()) || m.Name.Contains(ConfigurationManager.AppSettings["csvFileNameFormat2"].ToString()) || m.Name.Contains(ConfigurationManager.AppSettings["csvFileNameFormat3"].ToString())); foreach (var item1 in SftpFiles) { //Check the DataFile exist or not in database for duplicate if (!db.DataFiles.Any(m => (m.FileName == item1.FullName) || (m.FileName == item1.Name))) { DataFile objDataFile = new DataFile(); objDataFile.FileName = item1.FullName; objDataFile.DateOfFile = Convert.ToDateTime(objDataFileImporter.GetDateFromString(item1.Name)); objDataFile.IsInSftp = true; lstDataFile.Add(objDataFile); } } } if (lstDataFile.Count > 0) { //Save the changes for the new collection of DataFiles db.DataFiles.AddRange(lstDataFile); db.SaveChanges(); } retMessage = "Sucessfully Imported"; } } catch (Exception ex) { retMessage = ex.Message; throw ex; } return(new HttpResponseMessage() { Content = new StringContent(retMessage) }); }
public HttpResponseMessage DeleteLocationIndicator(LocationIndicatorViewModel objLocation) { try { using (ThomsonDbContext db = new ThomsonDbContext(objLocation.SiteName)) { LocationIndicator objLocationIndicator = db.LocationIndicator.Where(b => b.LoctionIndicatorId == objLocation.LoctionIndicatorId).FirstOrDefault(); db.LocationIndicator.Remove(objLocationIndicator); db.SaveChanges(); } } catch (Exception ex) { throw ex; } return(Request.CreateResponse(HttpStatusCode.OK)); }
public HttpResponseMessage Delete(LocationIndicatorViewModel objLocation) { try { using (ThomsonDbContext db = new ThomsonDbContext(objLocation.SiteName)) { var objAreaOfInterest = db.InterestLocation.Where(a => a.AreaOfInterestId == objLocation.AreaOfInterestId).FirstOrDefault(); db.InterestLocation.Remove(objAreaOfInterest); db.SaveChanges(); } } catch (Exception ex) { throw ex; } return(Request.CreateResponse(HttpStatusCode.OK)); }
public HttpResponseMessage Details(int?id, string SiteName) { LocationIndicator locationIndicator = null; if (id == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } using (ThomsonDbContext db = new ThomsonDbContext(SiteName)) { locationIndicator = db.LocationIndicator.Find(id); if (locationIndicator == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } return(Request.CreateResponse(locationIndicator)); }
public List <LocationIndicatorViewModel> Index(string SiteName) { //Assign the Default Site if (!string.IsNullOrEmpty(SiteName) || SiteName == null) { SiteName = "Discovery1"; } List <LocationIndicatorViewModel> lstLocationIndicatorViewModel = new List <LocationIndicatorViewModel>(); try { using (var db = new ThomsonDbContext(SiteName)) { var interLocationsData = db.InterestLocation.ToList(); foreach (var item in interLocationsData.GroupBy(m => new { m.AreaOfInterestId, m.Name })) { LocationIndicatorViewModel objLocationIndicatorViewModel = new LocationIndicatorViewModel(); objLocationIndicatorViewModel.AreaOfInterestId = item.Key.AreaOfInterestId; objLocationIndicatorViewModel.Name = item.Key.Name; foreach (var item1 in db.LocationIndicator.Where(m => m.AreaOfInterestId == objLocationIndicatorViewModel.AreaOfInterestId)) { objLocationIndicatorViewModel.LoctionIndicator += item1.LoctionIndicator + ","; } foreach (var item2 in db.NeighBourAreas.Where(m => m.AreaId == objLocationIndicatorViewModel.AreaOfInterestId)) { objLocationIndicatorViewModel.NeighBourName += item2.AreaCode + ","; } lstLocationIndicatorViewModel.Add(objLocationIndicatorViewModel); } } } catch (Exception ex) { throw ex; } return(lstLocationIndicatorViewModel); }
public HttpResponseMessage UpdateParameters(string key, string value, string ConnectionString) { try { using (ThomsonDbContext db = new ThomsonDbContext(ConnectionString)) { Parameter objParameter = db.Parameters.FirstOrDefault(m => m.Name == key); objParameter.Value = value; db.Entry(objParameter).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(new HttpResponseMessage() { Content = new StringContent("successfully Updated") }); } } catch (Exception ex) { Log.Error(ex.Message); throw ex; } }
public HttpResponseMessage Create(LocationIndicatorViewModel objlocationIndicator) { InterestLocation locationModel = new InterestLocation(); objlocationIndicator.SiteName = "Discovery1"; using (ThomsonDbContext db = new ThomsonDbContext(objlocationIndicator.SiteName)) { if (!string.IsNullOrEmpty(objlocationIndicator.Name)) { locationModel.Name = objlocationIndicator.Name; db.InterestLocation.Add(locationModel); db.SaveChanges(); } var location = db.InterestLocation.Where(a => a.Name == locationModel.Name).SingleOrDefault(); if (!string.IsNullOrEmpty(objlocationIndicator.LoctionIndicator)) { LocationIndicator indicatorModel = new LocationIndicator(); indicatorModel.LoctionIndicator = objlocationIndicator.LoctionIndicator; indicatorModel.AreaOfInterestId = location.AreaOfInterestId; db.LocationIndicator.Add(indicatorModel); } if (!string.IsNullOrEmpty(objlocationIndicator.NeighBourName)) { NeighBourArea objNeighBourArea = new NeighBourArea(); objNeighBourArea.AreaId = location.AreaOfInterestId; objNeighBourArea.AreaCode = objlocationIndicator.NeighBourName; db.NeighBourAreas.Add(objNeighBourArea); } db.SaveChanges(); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public HttpResponseMessage Edit(LocationIndicatorViewModel locationIndicator) { try { using (ThomsonDbContext db = new ThomsonDbContext(locationIndicator.SiteName)) { var objInterestLoction = db.InterestLocation.Where(p => p.AreaOfInterestId == locationIndicator.AreaOfInterestId).FirstOrDefault(); objInterestLoction.Name = locationIndicator.Name; db.Entry(objInterestLoction).State = EntityState.Modified; //var ab = fc["LoctionIndicator"].ToString(); //foreach (var item in fc["LoctionIndicator"].Split(',')) //{ // if (!string.IsNullOrEmpty(item)) // { // LocationIndicator indicatorModel = new LocationIndicator(); // indicatorModel.LoctionIndicator = item.ToString(); // indicatorModel.AreaOfInterestId = objInterestLoction.AreaOfInterestId; // db.LocationIndicator.Add(indicatorModel); // } //} //foreach (var item in fc["NeighBourName"].Split(',')) //{ // if (!string.IsNullOrEmpty(item)) // { // NeighBourArea objNeighBourArea = new NeighBourArea(); // objNeighBourArea.AreaCode = item; // objNeighBourArea.AreaId = locationIndicator.AreaOfInterestId; // db.NeighBourAreas.Add(objNeighBourArea); // } //} foreach (var Item in locationIndicator.lstMapLocations) { var objlocationIndicator = new LocationIndicator(); if (db.LocationIndicator.Any(m => m.LoctionIndicatorId == Item.LoctionIndicatorId)) { objlocationIndicator = db.LocationIndicator.Where(m => m.AreaOfInterestId == locationIndicator.AreaOfInterestId && m.LoctionIndicatorId == Item.LoctionIndicatorId).FirstOrDefault(); objlocationIndicator.LoctionIndicator = Item.LoctionIndicator; db.Entry(objlocationIndicator).State = EntityState.Modified; } else { objlocationIndicator.LoctionIndicator = Item.LoctionIndicator; objlocationIndicator.AreaOfInterestId = Item.AreaOfInterestId; db.LocationIndicator.Add(objlocationIndicator); } } foreach (var item in locationIndicator.lstNeighBourMaps) { var ObjNeighBourArea = new NeighBourArea(); if (db.NeighBourAreas.Any(m => m.NeighbourAreaId == item.NeighBourId)) { ObjNeighBourArea = db.NeighBourAreas.Where(m => m.NeighbourAreaId == item.NeighBourId && m.AreaId == locationIndicator.AreaOfInterestId).FirstOrDefault(); ObjNeighBourArea.AreaCode = item.NeighBourName; db.Entry(ObjNeighBourArea).State = EntityState.Modified; } else { ObjNeighBourArea.AreaCode = item.NeighBourName; ObjNeighBourArea.AreaId = item.AreaOfInterestId; db.NeighBourAreas.Add(ObjNeighBourArea); } } db.SaveChanges(); } } catch (Exception ex) { } return(Request.CreateResponse(HttpStatusCode.OK)); }