コード例 #1
0
        public JsonResult Create(CreateVM model)
        {
            var result = new JsonResultBO(true);

            try
            {
                if (ModelState.IsValid)
                {
                    if (!String.IsNullOrEmpty(model.Code) && _dm_DulieuDanhmucService.CheckCodeExisted(model.GroupId, model.Code.ToUpper()))
                    {
                        throw new Exception(String.Format("Mã nhóm {0} đã tồn tại!", model.Code.ToUpper()));
                    }
                    var dulieuDanhmuc = new DM_DulieuDanhmuc();
                    dulieuDanhmuc.GroupId  = model.GroupId;
                    dulieuDanhmuc.Name     = model.Name;
                    dulieuDanhmuc.Code     = model.Code.ToUpper();
                    dulieuDanhmuc.Priority = model.Priority;
                    dulieuDanhmuc.Note     = model.Note;
                    _dm_DulieuDanhmucService.Create(dulieuDanhmuc);
                    _ILog.Info(String.Format("Thêm mới nhóm danh mục {0}", dulieuDanhmuc.Name));
                }
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = ex.Message;
                _ILog.Error("Lỗi ở nhóm danh mục", ex);
            }
            return(Json(result));
        }
コード例 #2
0
        public JsonResult Delete(long id)
        {
            JsonResultBO result = new JsonResultBO(true);

            try
            {
                DM_DulieuDanhmuc entity = _dm_DulieuDanhmucService.GetById(id);
                if (entity != null)
                {
                    _dm_DulieuDanhmucService.Delete(entity);
                    result.Message = "Xóa danh mục thành công";
                    _ILog.Info(result.Message);
                }
                else
                {
                    result.Status  = false;
                    result.Message = "Danh mục không tồn tại";
                }
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = "Xóa danh mục không thành công";
                _ILog.Error("Xóa danh mục không thành công", ex);
            }
            return(Json(result));
        }