/// <summary> /// 保存页面操作(新增、修改) /// </summary> /// <returns></returns> public JsonResult SaveDemoOneData(Guid?id) { try { //标识唯一性验证 //以下代码注释去掉会发生错误,只能添加一条数据 // var smodel = dbContext.Set<DemoOne>().FirstOrDefault(so => so.Id != id); //if (smodel != null) // return Json(new { Code = 1, Msg = "该标识已存在!" }); DemoOne model = dbContext.Set <DemoOne>().FirstOrDefault(so => so.Id == id); if (model == null) { model = new DemoOne(); this.ToModel(model); model.Id = Guid.NewGuid(); model.CreateUserId = SSOClient.UserId; model.CreateTime = DateTime.Now; dbContext.Set <DemoOne>().Add(model); } else { this.ToModel(model); } dbContext.SaveChanges(); return(Json(new { Code = 0, Msg = "保存成功!" })); } catch (Exception ex) { LogHelper.SaveLog(ex); return(Json(new { Code = 1, Msg = "服务器异常,请联系管理员!" })); } }
public void Add_Test() { int result = DemoOne.Add(2, 3); Assert.Equal(5, result); }
public static int AddExternal(int c, int d) { return(DemoOne.Add(c, d)); }