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()); }
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(); }
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(); }
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(); }
/// <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(); }
public void Create(User item) { Role role = new Role { Name = "неопеределен" }; item.Role = role; newsContext.Entry(item); newsContext.Users.Add(item); newsContext.SaveChanges(); }
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); }
/// <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); }
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 })); }
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(); }
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()); }
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()); }
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()); }
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()); }
public static void UpdateNews(News news) { using (var context = new NewsContext()) { context.Entry(news).State = EntityState.Modified; context.SaveChanges(); } }
// 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)); }
public async Task UpdateAsync(ApplicationUser user) { if (user == null) { throw new ArgumentNullException(); } context.Entry(user).State = EntityState.Modified; await context.SaveChangesAsync(); }
/* 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())); }
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)); }
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)); }
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)); }
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)); }
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)); }
public ActionResult Edit(Tag tag) { if (ModelState.IsValid) { db.Entry(tag).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tag)); }
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)); }
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)); }
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(); }
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)); }
private void ChangeEntityState(T entity, EntityState state) { var entry = context.Entry(entity); if (entry.State == EntityState.Detached) { set.Attach(entity); } entry.State = state; }