Ejemplo n.º 1
0
        public Article Add(Article article)
        {
            using (var ctx = new TOFELDBContext())
            {
                var result = ctx.Articles.Add(article);
                ctx.SaveChanges();

                return(result);
            }
        }
Ejemplo n.º 2
0
        public IEnumerable <Article> AddRange(IEnumerable <Article> articles)
        {
            using (var ctx = new TOFELDBContext())
            {
                var result = ctx.Articles.AddRange(articles);
                ctx.SaveChanges();

                return(result);
            }
        }
Ejemplo n.º 3
0
        public bool Delete(int id)
        {
            using (var ctx = new TOFELDBContext())
            {
                try
                {
                    var deleteCandidate = ctx.Articles.Find(id);
                    if (deleteCandidate != null)
                    {
                        ctx.Articles.Remove(deleteCandidate);
                    }

                    ctx.SaveChanges();

                    return(true);
                }
                catch (Exception exc)
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 4
0
        public Article Update(Article item)
        {
            using (var ctx = new TOFELDBContext())
            {
                var updateCandidate = ctx.Articles.Find(item.ArticleId);
                if (updateCandidate != null)
                {
                    try
                    {
                        ctx.Articles.Attach(item);
                        ctx.Entry(item).State = EntityState.Modified;

                        ctx.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }

                return(updateCandidate);
            }
        }