/// <summary>
        /// Creates and stores and RFData reading in the local database.
        /// </summary>
        /// <param name="data">The RFData reading to be created/stored.</param>
        public static void AddRFData(RFData data)
        {
            if (VerifyRFData(data))
            {
                using (RTDbContext Context = InitializeDatabaseContext())
                {
                    // add the rf data to the list in appointment
                    data.Appointment.RFDatas.Add(data);

                    // add the rf data to the database
                    Context.RFDatas.AddOrUpdate(data);

                    Context.Entry(data.Appointment.User).State = EntityState.Unchanged;
                    Context.Entry(data.Appointment).State      = EntityState.Unchanged;
                    if (data.Appointment.Orientation != null)
                    {
                        Context.Entry(data.Appointment.Orientation).State = EntityState.Unchanged;
                    }
                    if (data.Appointment.CelestialBody != null)
                    {
                        if (data.Appointment.CelestialBody.Coordinate != null)
                        {
                            Context.Entry(data.Appointment.CelestialBody.Coordinate).State = EntityState.Unchanged;
                        }
                        Context.Entry(data.Appointment.CelestialBody).State = EntityState.Unchanged;
                    }
                    Context.Entry(data.Appointment.SpectraCyberConfig).State = EntityState.Unchanged;
                    Context.Entry(data.Appointment.Telescope).State          = EntityState.Unchanged;

                    // Only perform the following operations on a real telescope
                    // (i.e. the fields will not be null)
                    if (data.Appointment.Telescope.Location != null)
                    {
                        Context.Entry(data.Appointment.Telescope.Location).State = EntityState.Unchanged;
                    }

                    if (data.Appointment.Telescope.CurrentOrientation != null)
                    {
                        Context.Entry(data.Appointment.Telescope.CurrentOrientation).State = EntityState.Unchanged;
                    }

                    if (data.Appointment.Telescope.CalibrationOrientation != null)
                    {
                        Context.Entry(data.Appointment.Telescope.CalibrationOrientation).State = EntityState.Unchanged;
                    }

                    Context.SaveChanges();
                }
            }
        }
        /// <summary>
        /// Adds an appointment to the database
        /// </summary>
        public static void AddAppointment(Appointment appt)
        {
            using (RTDbContext Context = InitializeDatabaseContext())
            {
                if (createUser == false)
                {
                    // we have this line so that we do not add another user
                    Context.Entry(appt.User).State = EntityState.Unchanged;
                }
                else
                {
                    Context.Users.Add(appt.User);
                    createUser = false;
                }

                if (Context.CelestialBodies.Any(t => t.Id == appt.CelestialBody.Id) == false)
                {
                    if (Context.Coordinates.Any(t => t.Id == appt.CelestialBody.Coordinate.Id))
                    {
                        Context.Entry(appt.CelestialBody.Coordinate).State = EntityState.Unchanged;
                    }

                    Context.CelestialBodies.Add(appt.CelestialBody);
                }
                if (Context.Orientations.Any(t => t.Id == appt.Orientation.Id) == false)
                {
                    Context.Orientations.Add(appt.Orientation);
                }
                if (Context.SpectraCyberConfigs.Any(t => t.Id == appt.SpectraCyberConfig.Id) == false)
                {
                    Context.SpectraCyberConfigs.Add(appt.SpectraCyberConfig);
                }

                Context.Entry(appt.Telescope).State = EntityState.Unchanged;

                Context.Appointments.Add(appt);
                SaveContext(Context);

                // Add coordinates
                List <Appointment> alist = Context.Appointments.ToList <Appointment>();
                foreach (Coordinate c in appt.Coordinates)
                {
                    c.apptId = alist[alist.Count - 1].Id;
                    Context.Coordinates.AddOrUpdate(c);
                }
                SaveContext(Context);
            }
        }
 /// <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();
         }
     }
 }
Пример #4
0
        /// <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();
            //}
        }
Пример #5
0
        /// <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>
        /// 编辑旅游线路信息
        /// </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);
        }
Пример #8
0
        /// <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();
        }
Пример #9
0
        /// <summary>
        /// 编辑简介仁怀
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public void Edit(IntroduceInput input)
        {
            var introduceId = 0;
            var model       = new Introduce
            {
                Title = input.Title,
                //VideoUrl= HttpPathCombine(_imgPath,input.VideoUrl)
                VideoUrl = input.VideoUrl
                           //ImgUrl = Path.Combine(imgPath,input.ImgUrl),
                           //Content = input.Content
            };

            //try
            //{
            using (var db = new RTDbContext())
            {
                var oldModel = db.Introduces.FirstOrDefault();
                if (oldModel == null)
                {
                    db.Introduces.Add(model);
                    db.SaveChanges();
                    introduceId = model.Id;
                }
                else
                {
                    oldModel.Title    = model.Title;
                    oldModel.VideoUrl = model.VideoUrl;
                    //oldModel.ImgUrl = model.ImgUrl;
                    //oldModel.Content = model.Content;
                    db.Entry(oldModel).State = EntityState.Modified;
                    db.SaveChanges();
                    introduceId = oldModel.Id;
                }

                _detail.AddOrEdit(new AddOrEditDetailInput
                {
                    ProjectId  = introduceId,
                    ImgUrl     = HttpPathCombine(_imgPath, input.BigImgUrl),
                    Paragraphs = input.Contents
                }, db);

                db.SaveChanges();
            }
            //}
            //catch(Exception e)
            //{
            //    return false;
            //}
        }
        public JsonResult ListOrder([FromBody] ListingHex listing)
        {
            bool valid = ListingEntry.TryParse(_rpc, _db, listing, out var result, out var error, true);


            //If we got a valid one, mark it as active, and save it to the db
            if (valid)
            {
                result.Active = true;
                //Listings can be updated if they use the same UTXO as a previously uploaded tx
                if (_db.Entry(result)?.State == EntityState.Detached)
                {
                    _db.Listings.Add(result);
                }
                _db.SaveChanges();
            }

            return(new JsonResult(new ListingResult(valid, result, error)));
        }
Пример #11
0
        public void Edit(HomePageInput input)
        {
            var imgPath = ResourcePath.HomePage;
            var model   = new HomePage
            {
                FirstImgUrl = HttpPathCombine(imgPath, input.FirstImgUrl),
                ThirdImgUrl = HttpPathCombine(imgPath, input.ThirdImgUrl)
            };

            if (input.SecondImgUrlList != null && input.SecondImgUrlList.Count != 0)
            {
                input.SecondImgUrlList = input.SecondImgUrlList.Select(p => HttpPathCombine(imgPath, p)).ToList();
                model.SecondImgUrl     = string.Join("\n", input.SecondImgUrlList);
            }
            //try
            //{
            using (var db = new RTDbContext())
            {
                var oldModel = db.HomePages.FirstOrDefault();
                if (oldModel == null)
                {
                    db.HomePages.Add(model);
                }
                else
                {
                    oldModel.FirstImgUrl     = model.FirstImgUrl;
                    oldModel.SecondImgUrl    = model.SecondImgUrl;
                    oldModel.ThirdImgUrl     = model.ThirdImgUrl;
                    db.Entry(oldModel).State = EntityState.Modified;
                }
                db.SaveChanges();
            }
            //}
            //catch(Exception e)
            //{
            //    return false;
            //}
        }