public IActionResult EditArticle(ArticleViewModel model) { //model validation check if (!ModelState.IsValid) { //sth wrong. Return to the page with model & error data return(View("EditArticle", model)); } //get article and update its values var article = _context.Article.Where(a => a.ArticleID == model.ArticleID).FirstOrDefault(); if (article != null) { article.Title = model.Title.ToUpper(); article.Text = model.Text; article.Author = model.Author; article.PublishDate = model.PublishDate; article.EventDate = DateTime.Now; article.EditorEmail = HttpContext.Session.GetString("SessionKeyEmail"); } _context.Update(article); _context.SaveChanges(); //go back to Publish page return(RedirectToAction("Publish", "Home")); }
public async Task <IActionResult> Edit(int id, [Bind("QuestionID,Email,QuestionText")] Question question) { if (id != question.QuestionID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(question); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!QuestionExists(question.QuestionID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(question)); }
public async Task <IActionResult> Edit(int id, Teammember teammember) { if (id != teammember.Id) { return(NotFound()); } if (ModelState.IsValid) { try { uploadphote(teammember); _context.Update(teammember); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeammemberExists(teammember.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(teammember)); }
public async Task <IActionResult> Edit(int id, [Bind("MediaId,Path,NewsId")] Media media) { if (id != media.MediaId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(media); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MediaExists(media.MediaId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["NewsId"] = new SelectList(_context.News, "NewsId", "LitleTitle", media.NewsId); return(View(media)); }
public async Task <NewsPost> Put(NewsPost updateNewsPost) { _context.Update(updateNewsPost); await _context.SaveChangesAsync(); return(updateNewsPost); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description")] Category category) { if (id != category.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(category.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,Title,DateOfCreation,DateOfPublication,IsPublish,PhotoName,Content,AdminId,SubTopicId")] Article article) { if (id != article.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(article); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ArticleExists(article.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AdminId"] = new SelectList(_context.Admins, "Id", "Id", article.AdminId); ViewData["SubTopicId"] = new SelectList(_context.SubTopics, "Id", "Id", article.SubTopicId); return(View(article)); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,Value,TopicId")] SubTopic subTopic) { if (id != subTopic.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(subTopic); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SubTopicExists(subTopic.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["TopicId"] = new SelectList(_context.Topics, "Id", "Id", subTopic.TopicId); return(View(subTopic)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,DisplayName,Priority")] Langs langs) { if (id != langs.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(langs); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LangsExists(langs.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(langs)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,PostTitle,PostContent,PostTeaser,AvatarImage,ViewCount,CateID")] Post post) { if (id != post.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(post); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PostExists(post.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CateID"] = new SelectList(_context.Categories, "ID", "CategoryName", post.CateID); return(View(post)); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,Value")] Topic topic) { if (id != topic.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(topic); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TopicExists(topic.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(topic)); }
public async Task <IActionResult> Edit(int id, [Bind("AuthorId,AuthorName,SurName,UserName,PassWord,Email")] Author author) { if (id != author.AuthorId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(author); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuthorExists(author.AuthorId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(author)); }
public ActionResult Edit(News news, HttpPostedFileBase fileAvatar) { if (fileAvatar == null) { news.Avatar = null; } else { news.Avatar = fileAvatar.FileName.ToString(); } NewsContext newsBL = new NewsContext(); if (newsBL.Update(news) >= 0) { string SaveLocation = Server.MapPath("~/Content/imgs") + "\\" + news.Avatar; if (fileAvatar != null) { try { fileAvatar.SaveAs(SaveLocation); } catch (Exception ex) { Response.Write("Error: " + ex.Message); } } return(RedirectToAction("Index")); } else { return(View()); } }
public async Task <IActionResult> Edit(long id, [Bind("Id,Title,PublisherId,NewsDate,Content,Image")] Models.News news) { if (id != news.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(news); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NewsExists(news.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(news)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,NewsId,LangId,NewsTitle,NewsContent,ViewCount,CreateDate,UpdateDate")] NewsLang newsLang) { if (id != newsLang.Id) { return(NotFound()); } if (ModelState.IsValid) { try { newsLang.UpdateDate = DateTime.Now; newsLang.ViewCount = 0; _context.Update(newsLang); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NewsLangExists(newsLang.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["NewsId"] = new SelectList(_context.News, "Id", "NewsTitle", newsLang.NewsId); ViewData["LangName"] = new SelectList(_context.Langs, "Id", "Name", newsLang.LangId); return(View(newsLang)); }
public async Task <IActionResult> Edit(int id, [Bind("NewsId,NewsTitle,LitleTitle,NewsSummary,NewsText,Source,ReadCount,NewsReleasetime,AuthorId,CategoryId")] News news) { if (id != news.NewsId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(news); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NewsExists(news.NewsId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AuthorId"] = new SelectList(_context.Authors, "AuthorId", "AuthorId", news.AuthorId); ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryId", news.CategoryId); return(View(news)); }
public async Task <IActionResult> Edit(int id, News news) { if (id != news.Id) { return(NotFound()); } if (ModelState.IsValid) { try { uploadphote(news); _context.Update(news); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NewsExists(news.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", news.CategoryId); return(View(news)); }
public async Task <IActionResult> Edit(int id, [Bind("UserId,Email")] User user) { if (id != user.UserId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.UserId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Details(int Id, NewsLang newslang) { int langInt = 0; var lang = Request.Cookies["lang"]; switch (lang) { case "az": { langInt = (int)LangEnums.az; break; } case "en": { langInt = (int)LangEnums.en; break; } case "ru": { langInt = (int)LangEnums.ru; break; } default: break; } if (Id == null) { return(NotFound()); } var newsLang = await context.NewsLang .Include(n => n.News) .FirstOrDefaultAsync(m => m.NewsId == Id && m.LangId == langInt); var query = await context.NewsLang.Where(x => x.LangId == langInt && x.NewsId == Id).FirstOrDefaultAsync(); //var query = await context.NewsLang.Where(x => x.Id == Id && x.LangId == langInt).SingleOrDefaultAsync(); if (query == null) { return(NotFound()); } query.ViewCount += 1; newslang.ViewCount = query.ViewCount; context.Update(newsLang); if (newsLang == null) { return(NotFound()); } //ViewBag.category = query.News.Category.CatName; //ViewBag.CatId = query.News.CategoryId; await context.SaveChangesAsync(); return(View(query)); }
public async Task Update([FromBody] NewsDto newsDto) { var news = _mapper.Map <News>(newsDto); _context.Update <News>(news); await _context.SaveChangesAsync(); _eventBus.Publish(new NewsUpdateEvent(news)); }
public NewsUpdateResult UpdateArticle(Article article) { try { _context.Update(article); _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(NewsUpdateResult.ConcurrencyError); } catch (DbUpdateException) { return(NewsUpdateResult.DbError); } return(NewsUpdateResult.Success); }
public bool UpdateGroup(PageGroups groups) { try { _db.Update(groups); return(true); } catch { return(false); } }
public bool UpdatePage(PagesTB pages) { try { _db.Update(pages); return(true); } catch { return(false); } }
public IActionResult Put([FromBody] Article article) { if (article == null) { return(BadRequest()); } if (ModelState.IsValid) { if (!context.Articles.Any(p => p.ArticleId == article.ArticleId)) { return(NotFound()); } article.TimeStamp = DateTime.Now; context.Update(article); context.SaveChanges(); return(Ok(article)); } else { return(BadRequest(ModelState)); } }