/// <summary> /// 编辑旅游信息 /// </summary> /// <param name="input"></param> public void Edit(AddOrEditTouristInformation input) { using (var db = new RTDbContext()) { var information = db.TouristInformations.FirstOrDefault(p => p.Id == input.Id); if (information == null) { throw new RTException("所选信息不存在"); } information.ImgUrl = HttpPathCombine(_imgPath, input.SmallImgUrl); information.Position = input.Position; information.Longitude = input.Longitude; information.Latitude = input.Latitude; information.Name = input.Name; information.Phone = input.Phone; information.Price = input.Price; //information.Distance = input.Distance; information.Type = input.Type; db.Entry(information).State = EntityState.Modified; db.SaveChanges(); if (information.Type == TouristInformationType.Hotel || information.Type == TouristInformationType.Winery) { _detail.AddOrEdit(new AddOrEditDetailInput { Classify = (int)information.Type, ProjectId = information.Id, ImgUrl = HttpPathCombine(_imgPath, input.BigImgUrl), Paragraphs = input.Contents }, db); db.SaveChanges(); } } }
/// <summary> /// 根据Id获取单个旅游线路信息 /// </summary> /// <param name="input"></param> /// <returns></returns> public TouristRouteForView GetTouristRoute(RTEntity <int> input) { var result = new TouristRouteForView(); using (var db = new RTDbContext()) { var route = db.TouristRoutes.FirstOrDefault(p => p.Id == input.Parameter); if (route == null) { throw new RTException("所选数据不存在"); } result.Id = route.Id; result.ImgUrl = route.ImgUrl; result.NeedDays = route.NeedDays; result.RouteName = route.RouteName; var detail = _detail.GetDetail(new GetDetailInput { ProjectId = route.Id }, db); if (detail == null) { return(result); } result.Contents = detail.Paragraphs; } return(result); }
//returns the Elevation Acc Blobs between the start and end times public static List <ElevationAccelerationBlob> GetElAccBlobData(long starttime, long endTime) { using (RTDbContext Context = InitializeDatabaseContext()) {//&& x.TimeCaptured < endTime return(Context.ElevationAccelerationBlobs.Where(x => x.FirstTimeCaptured >= starttime && x.FirstTimeCaptured <= endTime).ToList()); } }
/// <summary> /// 编辑景点 /// </summary> public void EditViewSpot(AddOrEditViewSpotDto input) { //using (TransactionScope tran = new TransactionScope()) //{ using (var db = new RTDbContext()) { int wisdomGuideId = GetWisdomGuideId(db); var model = db.WisdomGuideViewSpots.FirstOrDefault(p => p.Id == input.Id); if (model == null) { throw new RTException("所选数据不存在"); } model.ImgUrl = HttpPathCombine(_resourcePath, input.SmallImgUrl); //model.ViewSpotDescribe = input.ViewSpotDescribe; model.Position = input.Position; model.Phone = input.Phone; model.Longitude = input.Longitude; model.Latitude = input.Latitude; model.ViewSpotName = input.ViewSpotName; model.WisdomGuideId = wisdomGuideId; db.Entry(model).State = EntityState.Modified; int ViewSpotId = model.Id; _detail.AddOrEdit(new AddOrEditDetailInput { ProjectId = model.Id, ImgUrl = HttpPathCombine(_resourcePath, input.BigImgUrl), Paragraphs = input.Contents }, db); var list = db.WisdomGuideViewSpotVideos.Where(p => p.WisdomGuideViewSpotId == ViewSpotId).ToList(); if (list != null && list.Count() != 0) { for (int i = 0; i < list.Count; i++) { db.WisdomGuideViewSpotVideos.Remove(list[i]); } } if (input.VoiceList != null && input.VoiceList.Count != 0) { input.VoiceList.ForEach(item => { db.WisdomGuideViewSpotVideos.Add(new WisdomGuideViewSpotVideo { ImgUrl = HttpPathCombine(_resourcePath, item.ImgUrl), VoiceName = item.VoiceName, VoiceUrl = HttpPathCombine(_voicePath, item.VoiceUrl), WisdomGuideViewSpotId = ViewSpotId }); }); } db.SaveChanges(); } // tran.Complete(); //} }
/// <summary> /// Updates the appointment by saving the appt passed in. /// </summary> /// <param name="appt"> The appt that is being updated. </param> public static void UpdateAppointment(Appointment appt) { if (VerifyAppointmentStatus(appt)) { using (RTDbContext Context = InitializeDatabaseContext()) { // Update database appt with new status var db_appt = QueryAppointments(Context).ToList().Find(x => x.Id == appt.Id); if (db_appt != null) { db_appt.CelestialBody = appt.CelestialBody; db_appt.Coordinates = appt.Coordinates; db_appt.EndTime = appt.EndTime; db_appt.Orientation = appt.Orientation; db_appt.RFDatas = appt.RFDatas; db_appt.SpectraCyberConfig = appt.SpectraCyberConfig; db_appt.StartTime = appt.StartTime; db_appt.Status = appt.Status; db_appt.TelescopeId = appt.TelescopeId; db_appt.Type = appt.Type; db_appt.UserId = appt.UserId; SaveContext(Context); } } } }
/// <summary> /// 获取视频列表 /// </summary> public List <ViewSpotVideoDto> GetVideoList(RTEntity <int> input) { if (input == null) { throw new RTException("输入参数不能为空"); } var result = new List <ViewSpotVideoDto>(); using (var db = new RTDbContext()) { var viewPort = db.WisdomGuideViewSpots.FirstOrDefault(p => p.Id == input.Parameter); if (viewPort == null) { throw new RTException("所选数据不存在"); } var videoList = db.WisdomGuideViewSpotVideos.Where(p => p.WisdomGuideViewSpotId == viewPort.Id).ToList(); if (videoList != null && videoList.Count != 0) { videoList.ForEach(item => { result.Add(new ViewSpotVideoDto { ImgUrl = item.ImgUrl, VoiceName = item.VoiceName, VoiceUrl = item.VoiceUrl, }); }); } } return(result); }
/// <summary> /// add an array of sensor data to the apropriat table /// </summary> /// <param name="acc"></param> public static void AddSensorData(Acceleration[] acc, bool testflag = false) { Thread t = new Thread(() => { if (acc.Length <= 0) { return; } if (!USING_REMOTE_DATABASE) { using (RTDbContext Context = InitializeDatabaseContext()) { Context.Accelerations.AddRange(acc); //foreach(Temperature tump in temp) {} SaveContext(Context); } } }); t.Start(); if (testflag) { t.Join(); } }
/// <summary> /// 编辑旅游线路信息 /// </summary> /// <param name="input"></param> public void Edit(AddOrEditTouristRouteInput input) { using (var db = new RTDbContext()) { var routes = db.TouristRoutes.FirstOrDefault(p => p.Id == input.Id); if (routes == null) { throw new RTException("所选数据不存在"); } routes.ImgUrl = HttpPathCombine(_imgPath, input.ImgUrl); routes.NeedDays = input.NeedDays; routes.RouteName = input.RouteName; //routes.Content = input.Content; db.Entry(routes).State = EntityState.Modified; _detail.AddOrEdit(new AddOrEditDetailInput { ProjectId = routes.Id, ImgUrl = HttpPathCombine(_imgPath, input.ImgUrl), Paragraphs = input.Contents }, db); db.SaveChanges(); } }
/// <summary> /// Returns the updated Appointment from the database. /// </summary> public static Appointment GetUpdatedAppointment(Appointment appt) { using (RTDbContext Context = InitializeDatabaseContext()) { // Because the celestial body is not required, we only want to // perform these operations if one is present. if (appt.celestial_body_id != null) { Context.Entry(appt.CelestialBody).State = EntityState.Unchanged; if (appt.CelestialBody.Coordinate != null) { Context.Entry(appt.CelestialBody.Coordinate).State = EntityState.Unchanged; } } if (appt.Orientation != null) { Context.Entry(appt.Orientation).State = EntityState.Unchanged; } Context.Entry(appt.SpectraCyberConfig).State = EntityState.Unchanged; Context.Entry(appt.Telescope).State = EntityState.Unchanged; Context.Entry(appt.User).State = EntityState.Unchanged; Context.SaveChanges(); Context.Appointments.Attach(appt); Context.Entry(appt).Reload(); } return(appt); }
/// <summary> /// get acc between starttime and now from sensor location loc /// </summary> /// <param name="starttime"></param> /// <param name="endTime"> currently unused</param> /// <param name="loc"></param> /// <returns></returns> public static List <Acceleration> GetACCData(long starttime, long endTime, SensorLocationEnum loc) { using (RTDbContext Context = InitializeDatabaseContext()) {//&& x.TimeCaptured < endTime return(Context.Accelerations.Where(x => x.TimeCaptured > starttime && x.location_ID == (int)loc).ToList()); } }
/// <summary> /// 获取仁怀简介 /// </summary> /// <returns></returns> public IntroduceInput Detail() { var result = new IntroduceInput(); using (var db = new RTDbContext()) { var data = db.Introduces.FirstOrDefault(); if (data == null) { throw new RTException("数据不存在,请联系管理员"); } result.Title = data.Title; result.VideoUrl = data.VideoUrl; //result.ImgUrl = data.ImgUrl; //result.Content = data.Content; var detail = _detail.GetDetail(new GetDetailInput { ProjectId = data.Id }, db); if (detail == null) { return(result); } result.BigImgUrl = detail.ImgUrl; result.Contents = detail.Paragraphs; } return(result); }
/// <summary> /// Returns the object of the control room user that we will use for all control room movements /// </summary> public static User GetControlRoomUser() { User controlRoomUser = null; using (RTDbContext Context = InitializeDatabaseContext()) { // Use Include method to load related entities from the database List <User> users = Context.Users.SqlQuery("Select * from user WHERE first_name = 'control'").ToList <User>(); // users = users.Where(x => x.first_name == "control").ToList<User>(); if (users.Count() == 0) { users.Add(new User("control", "room", "*****@*****.**", NotificationTypeEnum.SMS)); createUser = true; } if (users.Count() > 1) { throw new System.InvalidOperationException("Too many control room users"); } controlRoomUser = users[0]; } return(controlRoomUser); }
/// <summary> /// 修改地图地址 /// </summary> public void ChangeMap(ChangeMapInput input) { if (input.ImgUrl == null || input.ImgUrl == "") { throw new RTException("请填写图片地址"); } input.ImgUrl = HttpPathCombine(_resourcePath, input.ImgUrl); //using (TransactionScope tran = new TransactionScope()) //{ using (var db = new RTDbContext()) { int wisdomGuideId = GetWisdomGuideId(db); var map = db.WisdomGuideMaps.FirstOrDefault(); if (map != null) { map.WisdomGuideId = wisdomGuideId; map.ImgUrl = input.ImgUrl; db.Entry(map).State = EntityState.Modified; } else { db.WisdomGuideMaps.Add(new WisdomGuideMap { WisdomGuideId = wisdomGuideId, ImgUrl = input.ImgUrl }); } db.SaveChanges(); } // tran.Complete(); //} }
/// <summary> /// Updates the appointment by saving the appt passed in. /// </summary> /// <param name="appt"> The appt that is being updated. </param> public static void UpdateAppointment(Appointment appt) { if (VerifyAppointmentStatus(appt)) { using (RTDbContext Context = InitializeDatabaseContext()) { // Add appointment Context.Appointments.AddOrUpdate(appt); // Retrieve all coordinates for appointment var coordsForAppt = Context.Coordinates.ToList <Coordinate>().Where(coord => coord.apptId == appt.Id); // Delete coordinates foreach (Coordinate c in coordsForAppt) { if (!appt.Coordinates.Any(co => co.Id == c.Id)) { Context.Coordinates.Remove(c); Context.SaveChangesAsync(); } } // Add coordinates foreach (Coordinate c in appt.Coordinates) { c.apptId = appt.Id; Context.Coordinates.AddOrUpdate(c); } Context.SaveChangesAsync(); } } }
/// <summary> /// 获取景点详情 /// </summary> /// <param name="input"></param> /// <returns></returns> public ViewSpotDetailOutput ViewSpotDetail(RTEntity <int> input) { if (input == null) { throw new RTException("输入参数不能为空"); } var result = new ViewSpotDetailOutput(); using (var db = new RTDbContext()) { var viewPort = db.WisdomGuideViewSpots.FirstOrDefault(p => p.Id == input.Parameter); if (viewPort == null) { throw new RTException("所选数据不存在"); } var detail = _detail.GetDetail(new GetDetailInput { ProjectId = viewPort.Id }, db); if (detail == null) { return(result); } result.BigImgUrl = detail.ImgUrl; result.Contents = detail.Paragraphs; } return(result); }
public GetMapInfoOutput GetMapInofo() { var result = new GetMapInfoOutput(); using (var db = new RTDbContext()) { var wisdom = db.WisdomGuides.FirstOrDefault(); if (wisdom == null) { throw new RTException("所选数据不存在"); } var map = db.WisdomGuideMaps.FirstOrDefault(p => p.WisdomGuideId == wisdom.Id); if (map != null) { result.ImgUrl = map.ImgUrl; } var spotList = db.WisdomGuideViewSpots.Where(p => p.WisdomGuideId == wisdom.Id); if (spotList != null && spotList.Count() != 0) { result.ViewSpotList = new List <ViewSpotSimpleInfo>(); spotList.ToList().ForEach(item => { result.ViewSpotList.Add(new ViewSpotSimpleInfo { Id = item.Id, ViewSpotName = item.ViewSpotName }); }); } } return(result); }
/// <summary> /// Adds the weather data /// </summary> public static void AddWeatherData(WeatherData weather) { using (RTDbContext Context = InitializeDatabaseContext()) { Context.Weather.Add(weather); SaveContext(Context); } }
/// <summary> /// FOR TEST PURPOSES ONLY. Adds the new dummy admin to the database. /// </summary> public static void AddNewDummyUser() { using (RTDbContext Context = InitializeDatabaseContext()) { Context.Database.ExecuteSqlCommand("INSERT INTO user (first_name, last_name, email_address, notification_type) VALUES ('control2', 'room', '*****@*****.**', 'ALL')"); SaveContext(Context); } }
/// <summary> /// 获取用于编辑景点的数据 /// </summary> /// <param name="input"></param> /// <returns></returns> public AddOrEditViewSpotDto GetViewSpotForEdit(RTEntity <int> input) { if (input == null) { throw new RTException("输入参数不能为空"); } var result = new AddOrEditViewSpotDto(); using (var db = new RTDbContext()) { var viewSpot = db.WisdomGuideViewSpots.FirstOrDefault(p => p.Id == input.Parameter); if (viewSpot == null) { throw new RTException("所选数据不存在"); } result.Id = viewSpot.Id; result.SmallImgUrl = viewSpot.ImgUrl; //result.Content = viewSpot.Content; //result.ImgUrl = viewSpot.ImgUrl; //result.ViewSpotDescribe = viewSpot.ViewSpotDescribe; result.Position = viewSpot.Position; result.Phone = viewSpot.Phone; result.Longitude = viewSpot.Longitude; result.Latitude = viewSpot.Latitude; result.ViewSpotName = viewSpot.ViewSpotName; result.WisdomGuideId = viewSpot.WisdomGuideId; var detail = _detail.GetDetail(new GetDetailInput { ProjectId = viewSpot.Id }, db); if (detail == null) { return(result); } result.BigImgUrl = detail.ImgUrl; result.Contents = detail.Paragraphs; var videoList = db.WisdomGuideViewSpotVideos.Where(p => p.WisdomGuideViewSpotId == viewSpot.Id).ToList(); if (videoList != null && videoList.Count != 0) { result.VoiceList = new List <ViewSpotVideoDto>(); videoList.ForEach(item => { result.VoiceList.Add(new ViewSpotVideoDto { ImgUrl = item.ImgUrl, VoiceName = item.VoiceName, VoiceUrl = item.VoiceUrl, WisdomGuideViewSpotId = item.WisdomGuideViewSpotId }); }); } } return(result); }
/// <summary> /// Returns the list of Appointments from the given context. /// </summary> private static DbQuery <Appointment> QueryAppointments(RTDbContext Context) { // Use Include method to load related entities from the database return(Context.Appointments.Include("Coordinates") .Include("CelestialBody.Coordinate") .Include("Orientation") .Include("RFDatas") .Include("SpectraCyberConfig")); }
/// <summary> /// Adds the radio telescope /// </summary> public static void AddRadioTelescope(RadioTelescope telescope) { using (RTDbContext Context = InitializeDatabaseContext()) { Context.RadioTelescope.Add(telescope); SaveContext(Context); logger.Info(Utilities.GetTimeStamp() + ": Added radio telescope to database"); } }
/// <summary> /// Adds a selected weather Threshold to the database /// </summary> /// <param name="weatherThreshold"></param> public static void AddWeatherThreshold(WeatherThreshold weatherThreshold) { using (RTDbContext Context = InitializeDatabaseContext()) { Context.WeatherThreshold.Add(weatherThreshold); SaveContext(Context); logger.Info(Utilities.GetTimeStamp() + ": Added WeatherThreshold to database"); } }
/// <summary> /// Adds the sensor status data /// </summary> public static void AddSensorStatusData(SensorStatus sensors) { using (RTDbContext Context = InitializeDatabaseContext()) { Context.SensorStatus.Add(sensors); SaveContext(Context); //logger.Info(Utilities.GetTimeStamp() + ": Added sensor status data to database"); } }
/// <summary> /// returns the most recent temerature for a given location /// </summary> /// <param name="loc"></param> /// <returns></returns> public static Temperature GetCurrentTemp(SensorLocationEnum loc) { using (RTDbContext Context = InitializeDatabaseContext()) {// && x.TimeCaptured < endTime) ) && x.TimeCaptured.Ticks < endTime.Ticks try { return(Context.Temperatures.Where(x => x.location_ID == (int)loc).OrderByDescending(x => x.TimeCapturedUTC).First()); } catch { return(new Temperature()); } } }
/// <summary> /// Returns the list of Appointments from the database. /// </summary> public static int GetTotalAppointmentCount() { int count = -1; using (RTDbContext Context = InitializeDatabaseContext()) { count = Context.Appointments.Count(); } return(count); }
/// <summary> /// Returns the list of Appointments from the database. /// </summary> public static List <Appointment> GetListOfAppointmentsForRadioTelescope(int radioTelescopeId) { List <Appointment> appts = new List <Appointment>(); using (RTDbContext Context = InitializeDatabaseContext()) { // Use Include method to load related entities from the database appts = QueryAppointments(Context).Where(x => x.TelescopeId == radioTelescopeId).ToList(); } return(appts); }
public static int GetTotalRFDataCount() { int count = -1; using (RTDbContext Context = InitializeDatabaseContext()) { count = Context.RFDatas.Count(); } return(count); }
/// <summary> /// Returns the list of Appointments from the database. /// </summary> public static List <RFData> GetListOfRFData() { List <RFData> appts = new List <RFData>(); using (RTDbContext Context = InitializeDatabaseContext()) { // Use Include method to load related entities from the database appts = Context.RFDatas.Include(t => t.Appointment).ToList <RFData>(); } return(appts); }
/// <summary> /// 添加或编辑详情信息 /// </summary> /// <param name="input"></param> /// <param name="db"></param> public void AddOrEdit(AddOrEditDetailInput input, RTDbContext db) { var detail = db.Details.FirstOrDefault(p => p.ModularType == _modularType && p.Classify == input.Classify && p.ProjectId == input.ProjectId); var detailId = 0; if (detail == null) { var model = new Detail { ModularType = _modularType, Classify = input.Classify, ProjectId = input.ProjectId, ImgUrl = input.ImgUrl }; db.Details.Add(model); db.SaveChanges(); detailId = model.Id; } else { detail.ModularType = _modularType; detail.Classify = input.Classify; detail.ProjectId = input.ProjectId; detail.ImgUrl = input.ImgUrl; db.Entry(detail).State = EntityState.Modified; detailId = detail.Id; } //删除原有文章信息 var list = db.DetailParagraphs.Where(p => p.DetailId == detailId).ToList(); if (list != null && list.Count() != 0) { for (int i = 0; i < list.Count(); i++) { db.DetailParagraphs.Remove(list[i]); } } if (input.Paragraphs != null && input.Paragraphs.Count != 0) { int i = 0; input.Paragraphs.ForEach(item => { i += 1; db.DetailParagraphs.Add(new DetailParagraph { DetailId = detailId, ParagraphIndex = i, ParagraphContent = item }); }); } db.SaveChanges(); }
/// <summary> /// Returns the list of Appointments from the database. /// </summary> public static int GetTotalRTCount() { int count = -1; using (RTDbContext Context = InitializeDatabaseContext()) { count = Context.RadioTelescope.Count(); } return(count); }