public virtual void DeleteRange(IList <T> datas)
        {
            using (messageEntities db = new messageEntities())
            {
                IList <T> list = new List <T>();
                foreach (T data in datas)
                {
                    Type           type    = data.GetType();
                    PropertyInfo[] members = type.GetProperties();
                    List <string>  ids     = new List <string>();
                    foreach (PropertyInfo m in members)
                    {
                        var temp = m.GetCustomAttribute <KeyAttribute>();
                        if (temp != null)
                        {
                            object obj = m.GetValue(data);
                            ids.Add(obj.ToString());
                            continue;
                        }
                    }
                    T entity = db.Set <T>().Find(ids.ToArray());
                    list.Add(entity);
                }

                if (list.Count > 0)
                {
                    foreach (var l in list)
                    {
                        db.Set <T>().Remove(l);
                    }

                    db.SaveChanges();
                }
            }
        }
 public virtual void Delete(T data)
 {
     using (messageEntities db = new messageEntities())
     {
         Type           type    = data.GetType();
         PropertyInfo[] members = type.GetProperties();
         List <string>  ids     = new List <string>();
         foreach (PropertyInfo m in members)
         {
             var temp = m.GetCustomAttribute <KeyAttribute>();
             if (temp != null)
             {
                 object obj = m.GetValue(data);
                 ids.Add(obj.ToString());
                 continue;
             }
         }
         T entity = db.Set <T>().Find(ids.ToArray());
         if (entity != default(T))
         {
             db.Set <T>().Remove(entity);
             db.SaveChanges();
         }
     }
 }
 public virtual void Update(T data)
 {
     using (messageEntities db = new messageEntities())
     {
         db.Entry <T>(data).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
 public void Update(string taskCode, int status)
 {
     using (DataAccess.messageEntities entity = new messageEntities())
     {
         var task = entity.mq_task.FirstOrDefault(p => p.enable == 1 && p.code == taskCode);
         if (task != null)
         {
             task.status = status;
             entity.SaveChanges();
         }
     }
 }
Example #5
0
 private void updateMessageStatus(TaskMessage msg, MessageStatus status)
 {
     using (var entity = new messageEntities())
     {
         var m = entity.mq_message.FirstOrDefault(p => p.code == msg.code);
         if (m != null)
         {
             m.status = (int)status;
             entity.SaveChanges();
         }
     }
 }
Example #6
0
        public void DBCreate(string title, string content)
        {
            Article article = new Article
            {
                Title   = title,
                Content = content,
                Time    = DateTime.Now
            };

            db.Article.Add(article);
            db.SaveChanges();
        }
Example #7
0
 public void UpdateStatus(string msg_code, MessageStatus status)
 {
     using (var entity = new messageEntities())
     {
         var m = entity.mq_message.FirstOrDefault(p => p.code == msg_code);
         if (m != null)
         {
             m.status     = (int)status;
             m.updatetime = DateTime.Now;
             entity.SaveChanges();
         }
     }
 }
Example #8
0
        public void UploadFile(string Name, string Url, int Size, string Type)
        {
            FileContent filecontent = new FileContent()
            {
                Name       = Name,
                Url        = Url,
                Size       = Size,
                Type       = Type,
                CreateTime = DateTime.Now
            };

            db.FileContent.Add(filecontent);
            db.SaveChanges();
        }
Example #9
0
        public void UploadFile(string FileName, string Url, int Size, string Type, string Account)
        {
            ForumAlbum data = new ForumAlbum()
            {
                FileName   = FileName,
                Url        = Url,
                Size       = Size,
                Type       = Type,
                Account    = Account,
                CreateTime = DateTime.Now
            };

            db.ForumAlbum.Add(data);
            db.SaveChanges();
        }
 public virtual T Add(T data)
 {
     using (messageEntities entity = new messageEntities())
     {
         entity.Set <T>().Add(data);
         try
         {
             entity.SaveChanges();
         }
         catch (System.Data.Entity.Validation.DbEntityValidationException ex)
         {
             throw ex;
         }
         return(data);
     }
 }
        public virtual void AddRange(IList <T> datas)
        {
            using (messageEntities entity = new messageEntities())
            {
                foreach (var data in datas)
                {
                    entity.Set <T>().Add(data);
                }

                try
                {
                    entity.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }
Example #12
0
 public void Insert(ForumMessage Data)
 {
     Data.CreateTime = DateTime.Now;
     db.ForumMessage.Add(Data);
     db.SaveChanges();
 }
Example #13
0
 public void Register(Members newMember)
 {
     newMember.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(newMember.Password, "SHA1");
     db.Members.Add(newMember);
     db.SaveChanges();
 }
Example #14
0
 public void InsertGustbooks(Guestbooks newData)
 {
     newData.CreateTime = DateTime.Now;
     db.Guestbooks.Add(newData);
     db.SaveChanges();
 }