Пример #1
0
        public JsonResult Create(T model)
        {
            try
            {
                ModelState.Remove("GUID");
                model.GUID = Guid.NewGuid().ToString("N");
                if (!ModelState.IsValid)
                {
                    return(Json(new { state = false, message = "输入验证不合法" }));
                }

                ContextService <T> service = new ContextService <T>(dbSet, hostelContext);
                service.AddEntity(model);

                return(Json(new { state = true, message = "操作成功" }));
            }
            catch
            {
                return(Json(new { state = false, message = "数据操作服务器错误,请确认数据是否完整" }));
            }
        }