Example #1
0
 public static List <T> GetAllFromEntity <T>() where T : class
 {
     using (var db = new TravianBotDB())
     {
         return(db.GetTable <T>().ToList());
     }
 }
Example #2
0
 public static void DeleteEntity <T>(T entity) where T : class
 {
     using (var db = new TravianBotDB())
     {
         db.Delete <T>(entity);
     }
 }
Example #3
0
 public static object InsertEntity <T>(T entity) where T : class
 {
     using (var db = new TravianBotDB())
     {
         return(db.InsertWithIdentity <T>(entity));
     }
 }
Example #4
0
 public static void UpdateEntity <T>(T entity) where T : class
 {
     using (var db = new TravianBotDB(cs))
     {
         db.Update <T>(entity);
     }
 }
Example #5
0
        //public static List<T> GetEntitiesByParameters<T>(Func<T, bool> where) where T : class
        //{
        //    using (var db = new TravianBotDB())
        //    {
        //        return db.GetTable<T>().Where<T>(where).Where<T>(GetLogicExclusion<T>()).ToList);
        //    }
        //}

        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T">linqToDb Table mapped</typeparam>
        /// <param name="pk"> Have to be of the same type of primary key atribute of T table mapped</param>
        /// <returns>T linqToDb mapped class</returns>
        public static T GetEntityByPK <T>(object pk) where T : class
        {
            using (var db = new TravianBotDB())
            {
                var pkName     = typeof(T).GetProperties().Where(prop => prop.GetCustomAttributes(typeof(LinqToDB.Mapping.PrimaryKeyAttribute), false).Count() > 0).First();
                var expression = SimpleComparison <T>(pkName.Name, pk);

                return(db.GetTable <T>().Where <T>(expression).FirstOrDefault());
            }
        }
Example #6
0
        /// <summary>
        /// Excelent to use to get entities by FK
        /// </summary>
        /// <typeparam name="T">Entity To Filter From DB Mapped</typeparam>
        /// <typeparam name="D">Type of property to filter using Equals Comparer</typeparam>
        /// <param name="propertyName">Name of property</param>
        /// <param name="valueToFilter">Value to filter query</param>
        /// <returns>List of T</returns>
        public static List <T> GetAllEntititiesByPropertyValue <T, D>(string propertyName, D valueToFilter)
            where T : class
        {
            if (string.IsNullOrWhiteSpace(propertyName))
            {
                return(GetAllFromEntity <T>());
            }

            var expression = SimpleComparison <T, D>(propertyName, valueToFilter);

            using (var db = new TravianBotDB())
            {
                var data = db.GetTable <T>().Where <T>(expression).ToList();
                return(data);
            }
        }
Example #7
0
        //      public ObservableCollection<Building> Buildings
        //{
        //          get
        //          {
        //              return buildings;
        //          }
        //          set
        //          {
        //              Set(() => Buildings, ref buildings, value);
        //          }
        //      }

        public Village(int villageId, string villageName, int x, int y, bool isActive = false, bool isCapital = false)
        {
            this.villageId   = villageId;
            this.villageName = villageName;
            this.x           = x;
            this.y           = y;
            this.isActive    = isActive;
            this.isCapital   = isCapital;

            PropertyChanged += (s, e) =>
            {
                Task.Run(() =>
                {
                    using (var db = new TravianBotDB())
                    {
                        db.DB_Villages.Where(dV => dV.VillageId == VillageId)
                        .Set(dV => dV.VillageName, VillageName)
                        .Set(dV => dV.IsCapital, IsCapital).Update();
                    }
                });
            };

            //Buildings.CollectionChanged += Buildings_CollectionChanged;
        }