public JsonResult Save(XtZhbModel model) { ReturnModel returnModel; if (model.id > 0) { XtZhbModel temp = new XtzhbService().GetModel(model.id); if (temp == null) { return(Json(new ReturnModel { Code = 201, Msg = "账号不存在" }, JsonRequestBehavior.AllowGet)); } temp.zh = model.zh; temp.dh = model.dh; temp.jsid = model.jsid; temp.lxr = model.lxr; temp.bz = model.bz; returnModel = new XtzhbService().Update(temp); return(Json(returnModel, JsonRequestBehavior.AllowGet)); } model.createtime = DateTime.Now; model.yybh = GLYadmin.YYID; model.mm = md5.to32MD5("123456"); model.zt = 1; model.txlj = "/Content/assets/images/photo/" + new Random().Next(1, 24) + ".png"; returnModel = new XtzhbService().Add(model); return(Json(returnModel, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 登陆,移动端 /// </summary> /// <returns></returns> public XtZhbModel Login(string sjhm) { using (IDbConnection conn = new DapperConnection().DbConnection) { string sql = "select * from xt_zhb where lx=@lx and dh=@dh and zt=1"; XtZhbModel model = conn.Query <XtZhbModel>(sql, new { dh = sjhm, lx = 1 }).FirstOrDefault(); return(model); } }
/// <summary> /// 登陆,1医院,2渠道,3医院团险,4,团险企业 /// </summary> /// <returns></returns> public XtZhbModel Login(string zh, string mm, int lx) { using (IDbConnection conn = new DapperConnection().DbConnection) { string sql = "select * from xt_zhb where lx=@lx and mm=@mm and zh=@zh and zt=1"; XtZhbModel model = conn.Query <XtZhbModel>(sql, new { zh = zh, mm = mm, lx = lx }).FirstOrDefault(); return(model); } }
/// <summary> /// 获取单个账号 /// </summary> /// <param name="id">角色Id</param> /// <returns></returns> public XtZhbModel GetModelWithJs(int id) { try { using (IDbConnection conn = new DapperConnection().DbConnection) { string sql = "SELECT a.*,b.JSMC FROM xt_zhb a join xt_jsglb b on a.jsid=b.id WHERE a.Id=@Id"; XtZhbModel model = conn.Query <XtZhbModel>(sql, new { Id = id }).FirstOrDefault(); return(model); } } catch (Exception e) { Log.WriteLog(e.Message); return(null); } }
/// <summary> /// 获取单个账号 /// </summary> /// <param name="id">角色Id</param> /// <returns></returns> public XtZhbModel GetModel(int id) { try { using (IDbConnection conn = new DapperConnection().DbConnection) { string sql = "SELECT * FROM xt_zhb WHERE Id=@Id"; XtZhbModel model = conn.Query <XtZhbModel>(sql, new { Id = id }).FirstOrDefault(); return(model); } } catch (Exception e) { Log.WriteLog(e.Message); return(null); } }
public JsonResult AddOrEdit(int id = 0) { try { XtZhbModel model = new XtZhbModel(); if (id > 0) { model = xtzhbService.GetModel(id); } return(Json(new ReturnModel { Code = 200, Msg = "Success", Result = model })); } catch (Exception e) { return(Json(new ReturnModel { Code = 201, Msg = "获取账号失败" })); } }
public ReturnModel Add(XtZhbModel model) { try { //验证参数 if (string.IsNullOrWhiteSpace(model.zh)) { return new ReturnModel { Code = 201, Msg = "账号不能为空" } } ; if (string.IsNullOrWhiteSpace(model.mm)) { return new ReturnModel { Code = 201, Msg = "医院编号不能为空" } } ; if (string.IsNullOrWhiteSpace(model.dh)) { return new ReturnModel { Code = 201, Msg = "手机号不能为空" } } ; if (model.jsid.Equals(0)) { return new ReturnModel { Code = 201, Msg = "请选择角色" } } ; if (string.IsNullOrWhiteSpace(model.lxr)) { return new ReturnModel { Code = 201, Msg = "姓名不能为空" } } ; StringBuilder sbSql = new StringBuilder(); DynamicParameters paramList = new DynamicParameters(); paramList.Add("Zh", model.zh); paramList.Add("Mm", model.mm); paramList.Add("CreateTime", model.createtime); paramList.Add("Dh", model.dh); paramList.Add("Lxr", model.lxr); paramList.Add("Ys", model.ys); paramList.Add("Yybh", model.yybh); paramList.Add("Jsid", model.jsid); paramList.Add("Zt", model.zt); paramList.Add("Bz", model.bz); paramList.Add("QdId", model.QdId); paramList.Add("Lx", model.Lx); paramList.Add("Txlj", model.txlj); using (IDbConnection conn = new DapperConnection().DbConnection) { //判断重名 sbSql.Clear(); sbSql.Append("SELECT * FROM xt_zhb WHERE zh=@Zh"); JsModel sameName = conn.QueryFirstOrDefault <JsModel>(sbSql.ToString(), paramList); if (sameName != null) { return(new ReturnModel { Code = 201, Msg = "存在相同的账号名" }); } sbSql.Clear(); sbSql.Append("INSERT INTO xt_zhb (zh, mm, createtime, dh, lxr, ys, yybh, jsid, zt, bz,Lx,QdId,txlj) VALUES (@Zh, @Mm, @CreateTime, @Dh, @Lxr, @Ys, @Yybh, @Jsid, @Zt, @Bz,@Lx,@QdId,@Txlj)"); int result = conn.Execute(sbSql.ToString(), paramList); if (result.Equals(1)) { return(new ReturnModel { Code = 200, Msg = "保存成功" }); } return(new ReturnModel { Code = 201, Msg = "保存失败" }); } } catch (Exception e) { Log.WriteLog(e.Message); return(new ReturnModel { Code = 201, Msg = "保存失败" }); } }
/// <summary> /// 修改账号 /// </summary> /// <returns></returns> public ReturnModel Update(XtZhbModel model) { try { if (string.IsNullOrWhiteSpace(model.zh)) { return new ReturnModel { Code = 201, Msg = "账号不能为空" } } ; if (string.IsNullOrWhiteSpace(model.mm)) { return new ReturnModel { Code = 201, Msg = "医院编号不能为空" } } ; if (model.jsid.Equals(0)) { return new ReturnModel { Code = 201, Msg = "请选择角色" } } ; if (string.IsNullOrWhiteSpace(model.lxr)) { return new ReturnModel { Code = 201, Msg = "姓名不能为空" } } ; StringBuilder sbSql = new StringBuilder(); using (IDbConnection conn = new DapperConnection().DbConnection) { DynamicParameters paramList = new DynamicParameters(); paramList.Add("Id", model.id); paramList.Add("Zh", model.zh); paramList.Add("Mm", model.mm); paramList.Add("Dh", model.dh); paramList.Add("Lxr", model.lxr); paramList.Add("Ys", model.ys); paramList.Add("Yybh", model.yybh); paramList.Add("Jsid", model.jsid); paramList.Add("Zt", model.zt); paramList.Add("Bz", model.bz); //判断账号存在 sbSql.Append("SELECT * FROM xt_zhb WHERE Id=@Id"); XtZhbModel existModel = conn.QueryFirstOrDefault <XtZhbModel>(sbSql.ToString(), paramList); if (existModel == null) { return(new ReturnModel { Code = 201, Msg = "账号不存在" }); } //判断重名 sbSql.Clear(); sbSql.Append("SELECT * FROM xt_zhb WHERE id<>@Id AND zh=@Zh"); JsModel sameName = conn.QueryFirstOrDefault <JsModel>(sbSql.ToString(), paramList); if (sameName != null) { return(new ReturnModel { Code = 201, Msg = "存在相同的账号名" }); } //保存更新 sbSql.Clear(); sbSql.Append("UPDATE xt_zhb SET zh=@Zh, mm=@Mm, dh=@Dh, lxr=@Lxr, ys=@Ys, jsid=@Jsid, zt=@Zt, bz=@Bz WHERE Id=@Id"); int result = conn.Execute(sbSql.ToString(), paramList); if (result.Equals(1)) { return(new ReturnModel { Code = 200, Msg = "保存成功" }); } return(new ReturnModel { Code = 201, Msg = "保存失败" }); } } catch (Exception e) { Log.WriteLog(e.Message); return(new ReturnModel { Code = 201, Msg = "保存失败" }); } }