public async Task <ActionResult> Edit(string ANID) { if (string.IsNullOrEmpty(ANID)) { return(RedirectToAction("Index")); } Announce model = await db.Announces.FindAsync(ANID); if (model != null) { PostAnnounceView pmodel = new PostAnnounceView() { ANID = model.ANID, Title = model.Title, Content = model.Content }; return(View(pmodel)); } return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit(PostAnnounceView model) { if (!ModelState.IsValid) { return(View(model)); } Announce m = await db.Announces.FindAsync(model.ANID); if (m != null) { m.Content = model.Content; m.FromUID = User.Identity.GetUserId(); m.Title = model.Title; m.Time = DateTime.Now; TryUpdateModel(m); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }
public async Task <ActionResult> Post(PostAnnounceView model) { if (!ModelState.IsValid) { return(View(model)); } if (model.Content.Length == 0) { ModelState.AddModelError("", "请填写公告内容"); return(View(model)); } Announce an = new Announce() { Title = model.Title, Content = model.Content, FromUID = User.Identity.GetUserId() }; db.Announces.Add(an); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }