コード例 #1
0
 public ActionResult Create()
 {
     var model = new TopicModel();
     model.CreatedDate = DateTime.Now;
     model.Published = true;
     return View(model);
 }
コード例 #2
0
 public ActionResult Edit(int Id)
 {
     var entity = _topicService.GetById(Id);
     var model = new TopicModel();
     if (entity != null)
     {
         Mapper.CreateMap<Topic, TopicModel>();
         Mapper.Map(entity, model);
     }
     return View(model);
 }
コード例 #3
0
 public ActionResult CreateOrUpdate(TopicModel model)
 {
     var entity = model.Id > 0 ? _topicService.GetById(model.Id) : new Topic();
     Mapper.CreateMap<TopicModel, Topic>();
     Mapper.Map(model, entity);
     entity.LastUpdated = DateTime.Now;
     string msg = string.Empty;
     if (entity.Id == 0)
     {
         _topicService.Insert(entity);
         msg = "Thêm trang nội dung thành công !";
     }
     else
     {
         msg = "Cập nhật trang nội dung thành công !";
         _topicService.Update(entity);
     }
     TempData["Message"] = null;
     if (!String.IsNullOrEmpty(msg))
         TempData["Message"] = msg;
     return RedirectToAction("Edit", new { Id = entity.Id });
 }