예제 #1
0
        public static int Delete(params object[] id)
        {
            var db    = new DBcon <T>();
            var Table = db.Table.Find(id);

            Table.UpdateDate = DateTime.Now;
            Table.Deleted    = true;
            return(db.SaveChanges());
        }
예제 #2
0
        public static int UpdateRange(IEnumerable <T> tables)
        {
            var db = new DBcon <T>();

            foreach (var table in tables)
            {
                db.Entry(table).State = EntityState.Modified;
            }
            return(db.SaveChanges());
        }
예제 #3
0
        public static int DeleteRange(IEnumerable <T> ids)
        {
            var db = new DBcon <T>();

            foreach (var id in ids)
            {
                var Table = db.Table.Find(id);
                Table.Deleted = true;
            }
            return(db.SaveChanges());
        }
예제 #4
0
        public static int AddRange(List <T> tables)
        {
            var db = new DBcon <T>();

            foreach (var table in tables)
            {
                if (string.IsNullOrEmpty(table.UserID))
                {
                    throw new Exception("UserID empty you must enter valid UserID");
                }
                table.CreateDate = DateTime.Now;
                table.UpdateDate = DateTime.Now;
                table.Deleted    = false;
            }
            db.Table.AddRange(tables);
            return(db.SaveChanges());
        }
예제 #5
0
        public static int Update(T model)
        {
            var db   = new DBcon <T>();
            var db2  = new DBcon <T>();
            var data = db2.Table.Find(model.ID);

            if (data != null && data.Deleted != true)
            {
                model.UpdateDate      = DateTime.Now;
                model.CreateDate      = data.CreateDate;
                model.UserID          = data.UserID;
                db.Entry(model).State = EntityState.Modified;
                return(db.SaveChanges());
            }
            else
            {
                throw new DataStoreException("We can't find the selected data to update");
            }
        }
예제 #6
0
        public static int Add(T model)
        {
            if (string.IsNullOrEmpty(model.UserID) && typeof(T).Name != "Logger")
            {
                throw new DataStoreException("UserID Null");
            }
            var db = new DBcon <T>();

            model.CreateDate = DateTime.Now;
            model.UpdateDate = DateTime.Now;
            model.Deleted    = false;
            db.Table.Add(model);
            try
            {
                return(db.SaveChanges());
            }
            catch (Exception ex)
            {
                ExceptionHandler.GetLog(ex, model.UserID, LoggerModels.ExcptionType.UnknownError);
                throw new DataStoreException("UnKnown exception please look at the InnerException", ex);
            }
        }