public JsonResult Create(CreateVM model) { var result = new JsonResultBO(true); try { if (ModelState.IsValid) { if (!String.IsNullOrEmpty(model.GroupCode) && _dm_NhomDanhmucService.CheckGroupCodeExisted(model.GroupCode.ToUpper())) { throw new Exception(String.Format("Mã nhóm {0} đã tồn tại!", model.GroupCode.ToUpper())); } var nhomDanhmuc = new DM_NhomDanhmuc(); nhomDanhmuc.GroupName = model.GroupName; nhomDanhmuc.GroupCode = model.GroupCode.ToUpper(); _dm_NhomDanhmucService.Create(nhomDanhmuc); _ILog.Info(String.Format("Thêm mới nhóm danh mục {0}", nhomDanhmuc.GroupName)); } } catch (Exception ex) { result.Status = false; result.Message = ex.Message; _ILog.Error("Lỗi ở nhóm danh mục", ex); } return(Json(result)); }
public JsonResult Delete(long id) { JsonResultBO result = new JsonResultBO(true); try { DM_NhomDanhmuc entity = _dm_NhomDanhmucService.GetById(id); if (entity != null) { List <DM_DulieuDanhmuc> listDulieu = _dm_DulieuDanhmucService.GetListDataByGroupId(id); if (listDulieu != null && listDulieu.Count > 0) { _dm_DulieuDanhmucService.DeleteRange(listDulieu); _ILog.Info(String.Format("Xoá dữ liệu của danh mục {0} thành công", entity.GroupCode)); } _dm_NhomDanhmucService.Delete(entity); result.Message = "Xóa nhóm danh mục thành công"; _ILog.Info(result.Message); } else { result.Status = false; result.Message = "Nhóm danh mục không tồn tại"; } } catch (Exception ex) { result.Status = false; result.Message = "Xóa nhóm danh mục không thành công"; _ILog.Error("Xóa nhóm danh mục không thành công", ex); } return(Json(result)); }