Exemplo n.º 1
0
 public ActionResult Create()
 {
     var adViewModel = new AdViewModel
     { 
         SortOrder = 0
     };
     return View(adViewModel);
 }
Exemplo n.º 2
0
 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();
 }
Exemplo n.º 3
0
        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();
        }