public PartialViewResult CreateOrUpdate(string id) { var model = new NoiBanHanhViewModel(); if (string.IsNullOrEmpty(id)) { return(PartialView("~/Views/Role/_PartialCreateOrUpdateRole.cshtml", model)); } else { var noiBanHanh = _noiBanHanhService.Get(m => m.Id == id); model.Id = noiBanHanh.Id; model.Ten = noiBanHanh.Ten; model.MoTa = noiBanHanh.MoTa; model.TrangThai = noiBanHanh.TrangThai; model.NgayTao = noiBanHanh.NgayTao; model.NgayCapNhat = noiBanHanh.NgayCapNhat; return(PartialView("~/Views/Role/_PartialCreateOrUpdateRole.cshtml", model)); } }
public ActionResult CreateOrUpdate(NoiBanHanhViewModel model) { var noiBanHanh = string.IsNullOrEmpty(model.Id) ? new NoiBanHanh { NgayCapNhat = DateTime.Now } : _noiBanHanhService.Get(m => m.Id == model.Id); noiBanHanh.Ten = model.Ten; noiBanHanh.MoTa = model.MoTa; if (string.IsNullOrEmpty(model.Id)) { _noiBanHanhService.Insert(noiBanHanh); _functionLichSuHoatDongService.Create(ActionWithObject.Create, User.Identity.GetUserId(), "nơi ban hành: " + model.Ten); TempData["AlertMessage"] = "Tạo Mới Thành Công"; } else { _noiBanHanhService.Update(noiBanHanh); _functionLichSuHoatDongService.Create(ActionWithObject.Update, User.Identity.GetUserId(), "nơi ban hành: " + model.Ten); TempData["AlertMessage"] = "Cập Nhật Thành Công"; } return(RedirectToAction("Index")); }