Esempio n. 1
0
        public void InsertByMemberId(int memberId, Dictionary <string, string> news)
        {
            using (ABGNDBEntities context = new ABGNDBEntities())
            {
                string link        = news["link"];
                var    scrap       = context.Scraps.FirstOrDefault(x => x.Link == link);
                var    LoginedUser = context.Members.FirstOrDefault(x => x.MemberId == memberId);

                foreach (var sc in LoginedUser.Scraps)
                {
                    if (sc == scrap)
                    {
                        return;
                    }
                }

                if (scrap == null)
                {
                    scrap              = new Scrap();
                    scrap.PubDate      = DateTime.Now;
                    scrap.Title        = news["title"];
                    scrap.Description  = news["description"];
                    scrap.Link         = news["link"];
                    scrap.OriginalLink = news["originalLink"];
                }

                LoginedUser.Scraps.Add(scrap);
                context.SaveChanges();
            }
        }
Esempio n. 2
0
        public void InsertKeyword(int memberId, string str)
        {
            using (var context = new ABGNDBEntities())
            {
                // keyword 유무 확인
                var keyword = context.Keywords.FirstOrDefault(x => x.PushName == str);

                // member 에 keyword 있는지 확인
                var member = context.Members.FirstOrDefault(x => x.MemberId == memberId);

                foreach (var kw in member.Keywords)
                {
                    if (kw == keyword)
                    {
                        return;
                    }
                }

                // keyword 테이블에 없을 시 새로 생성
                if (keyword == null)
                {
                    keyword          = new Keyword();
                    keyword.PushDate = DateTime.Now;
                    keyword.PushName = str;
                }

                // 매핑 테이블에 추가
                member.Keywords.Add(keyword);
                context.SaveChanges();
            }
        }
Esempio n. 3
0
        public void Delete(T entity)
        {
            using (ABGNDBEntities context = new ABGNDBEntities())
            {
                context.Entry(entity).State = System.Data.Entity.EntityState.Deleted;

                context.SaveChanges();
            }
        }
Esempio n. 4
0
        public void Insert(T entity)
        {
            using (ABGNDBEntities context = new ABGNDBEntities())
            {
                context.Set <T>().Add(entity);
                context.Entry(entity).State = System.Data.Entity.EntityState.Added;

                context.SaveChanges();
            }
        }
Esempio n. 5
0
        public void DeleteKeyword(int memberId, string str)
        {
            using (var context = new ABGNDBEntities())
            {
                var keyword = context.Keywords.FirstOrDefault(x => x.PushName == str);

                context.Members.FirstOrDefault(x => x.MemberId == memberId).Keywords.Remove(keyword);
                context.SaveChanges();
            }
        }
Esempio n. 6
0
        public void DeleteScrap(int memberId, string link)
        {
            using (ABGNDBEntities context = new ABGNDBEntities())
            {
                var scrap  = context.Scraps.FirstOrDefault(x => x.Link == link);
                var member = context.Members.FirstOrDefault(x => x.MemberId == memberId);

                member.Scraps.Remove(scrap);
                context.SaveChanges();
            }
        }