public ActionResult Create() { var adViewModel = new AdViewModel { SortOrder = 0 }; return View(adViewModel); }
public async Task<ActionResult> Create(AdViewModel viewModel) { if (ModelState.IsValid) { var ad = adRepository.Create( new Ad { Name = viewModel.Name, Description = viewModel.Description, Place = 0, Type = 0, Src = viewModel.Src, Link = viewModel.Link, Status = 1, SortOrder = viewModel.SortOrder, Created = DateTime.Now }); await uow.SaveAsync(); return RedirectToAction("Index"); } ModelState.AddModelError("", "操作失败。"); return View(); }
public async Task<ActionResult> Edit(AdViewModel adViewModel) { if (ModelState.IsValid) { var ad = adRepository.FindById(adViewModel.Id); if (ad == null) { return HttpNotFound(); } ad.Name = adViewModel.Name; ad.Description = adViewModel.Description; ad.Src = adViewModel.Src; ad.Link = adViewModel.Link; ad.SortOrder = adViewModel.SortOrder; adRepository.Update(ad); await uow.SaveAsync(); return RedirectToAction("Index"); } ModelState.AddModelError("", "操作失败。"); return View(); }