コード例 #1
0
        public async Task <ActionResult <News> > PutDraft(int id, News nnews)
        {
            var news = await GetANews(id);

            if (news == null)
            {
                return(NotFound());
            }
            //var headers = _httpContextAccessor.HttpContext.Request.Headers;
            news.Content    = nnews.Content;
            news.Raw        = nnews.Raw;
            news.Title      = nnews.Title;
            news.Status     = 10;
            news.CreateTime = DateTime.Now;
            //news.JournalistId = int.Parse(headers["uid"]);
            _context.Entry(news).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NewsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public void Delete(int id)
        {
            NewsSource newsSource = newsContext.NewsSources.Find(id);

            newsContext.Entry(newsSource).Collection(p => p.News).Load();
            newsContext.NewsSources.Remove(newsSource);
            newsContext.SaveChanges();
        }
コード例 #3
0
        public virtual void Update(IEntity newObject)
        {
            var old = BringOne(newObject.Id);

            db.Entry(old).CurrentValues.SetValues(newObject);
            db.Entry(old).State = EntityState.Modified;
            db.SaveChanges();
        }
コード例 #4
0
        public void Delete(int id)
        {
            Rubric rubric = newsContext.Rubrics.Find(id);

            newsContext.Entry(rubric).Collection(p => p.News).Load();
            newsContext.Rubrics.Remove(rubric);
            newsContext.SaveChanges();
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        public virtual void Add(T entity)
        {
            //   _dbset.Add(entity);
            _context.Entry(entity).State = EntityState.Added;
            //    _context.Entry(entity).CurrentValues.SetValues(EntityState.Added);

            _context.SaveChanges();
        }
コード例 #6
0
ファイル: UserRepository.cs プロジェクト: Umkamaks/Repositiry
        public void Create(User item)
        {
            Role role = new Role {
                Name = "неопеределен"
            };

            item.Role = role;
            newsContext.Entry(item);
            newsContext.Users.Add(item);
            newsContext.SaveChanges();
        }
コード例 #7
0
        public async Task <ActionResult <NewsList> > GetNewsList(long id)
        {
            var newsItemList = await _context.NewsLists.FindAsync(id);

            if (newsItemList == null)
            {
                return(NotFound());
            }

            await _context.Entry(newsItemList).Collection(x => x.NewsItem).LoadAsync();

            return(newsItemList);
        }
コード例 #8
0
ファイル: Repository.cs プロジェクト: auto-taurus/Last
        /// <summary>
        /// 单个实体更新,需调用CommitChanges获SaveChangesAsync保存
        /// </summary>
        /// <param name="entity">实体</param>
        public virtual void Update(TEntity entity)
        {
            // Get entity's entry
            var entry = _BaseDb.Entry(entity);

            if (entry.State == EntityState.Detached)
            {
                // 将实体追加到上下文中,并跟踪实体
                _BaseDb.Set <TEntity>().Attach(entity);
            }
            entry.State = EntityState.Modified;
            _BaseDb.Set <TEntity>().Update(entity);
        }
コード例 #9
0
        public IActionResult EditNews(News news)
        {
            using (var client = new NewsContext())
            {
                // var result = client.News.Single(x => x.Id == news.Id);
                var result = client.News.Find(news.Id);

                result.Header   = news.Header;
                result.Intro    = news.Intro;
                result.Paragraf = news.Paragraf;
                result.Updated  = DateTime.Now;

                client.News.Attach(result);
                var entry = client.Entry(result);
                entry.State = EntityState.Modified;

                client.SaveChanges();
            }

            var removedMessage = string.Format("Nyheten med ID {0} ändrades.", news.Id);

            return(Json(new
            {
                success = true,
                Message = removedMessage
            }));
        }
コード例 #10
0
        public void UpdateDb(News news)
        {
            _context.ChangeTracker.Entries().Where(e => e.Entity != null).ToList().ForEach(e => e.State = EntityState.Detached);
            _context.Entry(news).State = EntityState.Modified;

            _context.SaveChanges();
        }
コード例 #11
0
        public async Task <IActionResult> PutTag(int id, Tag tag)
        {
            if (id != tag.TagID)
            {
                return(BadRequest());
            }

            _context.Entry(tag).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TagExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #12
0
 public IHttpActionResult PutNews(News news)
 {
     db.Entry(news).State = EntityState.Modified;
     db.SaveChanges();
     //return StatusCode(HttpStatusCode.OK);
     return(Ok());
 }
        public async Task <IActionResult> PutNews(int id, News news)
        {
            if (id != news.Id)
            {
                return(BadRequest());
            }

            _context.Entry(news).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NewsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #14
0
        public async Task <IActionResult> PutComment(int id, Comment Comment)
        {
            if (id != Comment.CommentID)
            {
                return(BadRequest());
            }

            _context.Entry(Comment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #15
0
        public async Task <IActionResult> PutArticle(int id, Article article)
        {
            if (id != article.ArticleID)
            {
                return(BadRequest());
            }

            _context.Entry(article).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArticleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #16
0
 public static void UpdateNews(News news)
 {
     using (var context = new NewsContext())
     {
         context.Entry(news).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #17
0
        // GET: Article/Details/id
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Article article = db.Articles.Find(id);

            if (article == null)
            {
                return(HttpNotFound());
            }
            article.Views          += 1;
            db.Entry(article).State = EntityState.Modified;
            db.SaveChanges();
            return(View(article));
        }
コード例 #18
0
 public async Task UpdateAsync(ApplicationUser user)
 {
     if (user == null)
     {
         throw new ArgumentNullException();
     }
     context.Entry(user).State = EntityState.Modified;
     await context.SaveChangesAsync();
 }
コード例 #19
0
        /* return  news by category */
        public IActionResult News(string Category)
        {
            ViewBag.name = Category;

            var CategoryN   = ctx.Categories.Single(a => a.CategoryName == Category);
            var NewsContext = ctx.Entry(CategoryN).Collection(b => b.News)
                              .Query().Include(b => b.Author).Include(b => b.Medias);

            return(View(NewsContext.ToList()));
        }
コード例 #20
0
 public ActionResult Edit([Bind(Include = "ID,UserName,Name,Surname,Mail")] Profile profile)
 {
     if (ModelState.IsValid)
     {
         db.Entry(profile).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(profile));
 }
コード例 #21
0
 public ActionResult Edit([Bind(Include = "ID,NewsPostID,Text,PublishDate,Author")] Comment comment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(comment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Details", "NewsPosts", new { id = comment.NewsPostID }));
     }
     return(View(comment));
 }
コード例 #22
0
 public ActionResult Edit([Bind(Include = "ID,Description")] Comment comment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(comment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(comment));
 }
コード例 #23
0
 public ActionResult Edit([Bind(Include = "ID,Title,Text,PublishDate,Author")] NewsPost newsPost)
 {
     if (ModelState.IsValid)
     {
         db.Entry(newsPost).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(newsPost));
 }
コード例 #24
0
 public ActionResult Edit([Bind(Include = "Id,NewsName,NewsText")] News news)
 {
     if (ModelState.IsValid)
     {
         db.Entry(news).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(news));
 }
コード例 #25
0
 public ActionResult Edit(Tag tag)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tag).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tag));
 }
コード例 #26
0
 public ActionResult Edit([Bind(Include = "PKAuthor,Name,BirthDate")] Author author)
 {
     if (ModelState.IsValid)
     {
         db.Entry(author).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(author));
 }
コード例 #27
0
 public ActionResult Edit([Bind(Include = "ID,Title,Text,Category,PostDate")] News news)
 {
     if (ModelState.IsValid)
     {
         db.Entry(news).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(news));
 }
コード例 #28
0
ファイル: BaseRepository.cs プロジェクト: qua11q7/NBCNewsMock
        public async Task Update(int id, TModel entity)
        {
            var local = _dbContext.Set <TModel>().Local.FirstOrDefault(entry => entry.ID.Equals(id));

            if (local != null)
            {
                _dbContext.Entry(local).State = EntityState.Detached;
            }
            _dbContext.Set <TModel>().Update(entity);
            await _dbContext.SaveChangesAsync();
        }
コード例 #29
0
 public ActionResult Edit([Bind(Include = "PKNews,Name,Type,PublishDate,FKAuthor")] News news)
 {
     if (ModelState.IsValid)
     {
         db.Entry(news).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.FKAuthor = new SelectList(db.Authors, "PKAuthor", "Name", news.FKAuthor);
     return(View(news));
 }
コード例 #30
0
ファイル: Repository.cs プロジェクト: churulik/SoftUni
        private void ChangeEntityState(T entity, EntityState state)
        {
            var entry = context.Entry(entity);

            if (entry.State == EntityState.Detached)
            {
                set.Attach(entity);
            }

            entry.State = state;
        }