public ActionResult AddUser(Base_UserInfo base_UserInfo) { var json = new JsonHelper() { Msg = "录入成功", Status = "n" }; try { if (!string.IsNullOrWhiteSpace(base_UserInfo.Mobile) && !Utils.CheckMobile(base_UserInfo.Mobile)) { json.Msg = "非法的手机号码"; return(Json(json, JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrWhiteSpace(base_UserInfo.Mail) && !Utils.IsValidEmail(base_UserInfo.Mail)) { json.Msg = "非法的邮箱地址"; return(Json(json, JsonRequestBehavior.AllowGet)); } if (UserBusiness.IsEffectiveUser(base_UserInfo.UserName)) { json.Msg = "用户名已存在,请更换一个名称"; return(Json(json, JsonRequestBehavior.AllowGet)); } base_UserInfo.UserType = (int)UserType.User; base_UserInfo.Password = Utils.MD5(base_UserInfo.Password); base_UserInfo.State = (int)UserState.Normal; IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); if (!base_UserInfoService.Add(base_UserInfo)) { json.Msg = "数据库更新失败"; } else { json.Status = "y"; UserBusiness.Init(); } } catch (Exception e) { json.Msg = e.Message; } return(Json(json, JsonRequestBehavior.AllowGet)); }
public ActionResult UserRegister(Base_UserInfo base_UserInfo) { var json = new JsonHelper() { Msg = "录入成功", Status = "n" }; try { if (!string.IsNullOrWhiteSpace(base_UserInfo.Mobile) && !Utils.CheckMobile(base_UserInfo.Mobile)) { json.Msg = "非法的手机号码"; return(Json(json, JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrWhiteSpace(base_UserInfo.Mail) && !Utils.IsValidEmail(base_UserInfo.Mail)) { json.Msg = "非法的邮箱地址"; return(Json(json, JsonRequestBehavior.AllowGet)); } if (UserBusiness.IsEffectiveUser(base_UserInfo.UserName)) { json.Msg = "用户名已存在,请更换一个名称"; return(Json(json, JsonRequestBehavior.AllowGet)); } base_UserInfo.UserType = (int)UserType.Customer; base_UserInfo.State = (int)UserState.Normal; base_UserInfo.Password = Utils.MD5(base_UserInfo.Password); IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); if (!base_UserInfoService.Add(base_UserInfo)) { json.Msg = "数据库更新失败"; } else { json.Status = "y"; json.Msg = "注册成功"; json.ReUrl = "../home/index"; UserBusiness.Init(); Utils.FormSignOut(); var authTicket = new FormsAuthenticationTicket(1, base_UserInfo.UserName, DateTime.Now, DateTime.Now.AddDays(1), base_UserInfo.REMEMBER_ME, base_UserInfo.ID.ToString()); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket)); if (authTicket.IsPersistent) { cookie.Expires = authTicket.Expiration; } Response.Cookies.Add(cookie); Session["loginUser"] = UserBusiness.GetUser(base_UserInfo.UserName); Session.Timeout = 300; } } catch (Exception e) { json.Msg = e.Message; } return(Json(json, JsonRequestBehavior.AllowGet)); }
public object EditMerch(Dictionary <string, object> dicParas) { try { string errMsg = string.Empty; string merchId = dicParas.ContainsKey("merchId") ? dicParas["merchId"].ToString() : string.Empty; string merchType = dicParas.ContainsKey("merchType") ? dicParas["merchType"].ToString() : string.Empty; string merchTag = dicParas.ContainsKey("merchTag") ? dicParas["merchTag"].ToString() : string.Empty; string merchStatus = dicParas.ContainsKey("merchStatus") ? dicParas["merchStatus"].ToString() : string.Empty; string merchAccount = dicParas.ContainsKey("merchAccount") ? dicParas["merchAccount"].ToString() : string.Empty; string merchName = dicParas.ContainsKey("merchName") ? dicParas["merchName"].ToString() : string.Empty; string openId = dicParas.ContainsKey("openId") ? dicParas["openId"].ToString() : string.Empty; string mobil = dicParas.ContainsKey("mobil") ? dicParas["mobil"].ToString() : string.Empty; string allowCreateSub = dicParas.ContainsKey("allowCreateSub") ? dicParas["allowCreateSub"].ToString() : string.Empty; string allowCreateCount = dicParas.ContainsKey("allowCreateCount") ? dicParas["allowCreateCount"].ToString() : string.Empty; string comment = dicParas.ContainsKey("comment") ? dicParas["comment"].ToString() : string.Empty; object[] merchFunction = dicParas.ContainsKey("merchFunction") ? (object[])dicParas["merchFunction"] : null; XCCloudUserTokenModel userTokenKeyModel = (XCCloudUserTokenModel)dicParas[Constant.XCCloudUserTokenModel]; string createUserId = userTokenKeyModel.LogId; int logType = userTokenKeyModel.LogType; #region 验证参数 if (string.IsNullOrEmpty(merchId)) { errMsg = "商户编号不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrWhiteSpace(merchType)) { errMsg = "商户类型不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!Utils.isNumber(merchType)) { errMsg = "商户类别不是Int类型"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrWhiteSpace(merchStatus)) { errMsg = "商户状态不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!Utils.isNumber(merchStatus)) { errMsg = "商户状态不是Int类型"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrEmpty(merchTag)) { errMsg = "商户标签不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!Utils.isNumber(merchTag)) { errMsg = "商户标签不是Int类型"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrWhiteSpace(merchAccount)) { errMsg = "商户账号不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (merchAccount.Length > 100) { errMsg = "商户账号不能超过100个字符"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrWhiteSpace(merchName)) { errMsg = "负责人不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (merchName.Length > 50) { errMsg = "负责人名称不能超过50个字符"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrWhiteSpace(openId)) { errMsg = "请选择微信昵称"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrWhiteSpace(mobil)) { errMsg = "手机号不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!Utils.CheckMobile(mobil)) { errMsg = "手机号不正确"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!string.IsNullOrEmpty(allowCreateSub) && !Utils.isNumber(allowCreateSub)) { errMsg = "是否允许创建子账号不是Int类型"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!string.IsNullOrEmpty(allowCreateCount) && !Utils.isNumber(allowCreateCount)) { errMsg = "账号数量不是Int类型"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!string.IsNullOrEmpty(comment) && comment.Length > 500) { errMsg = "备注不能超过500个字符"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } //获取用户基本信息 string unionId = string.Empty; if (!TokenMana.GetUnionId(openId, out unionId, out errMsg)) { return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } #endregion //开启EF事务 using (TransactionScope ts = new TransactionScope()) { try { IBase_MerchantInfoService base_MerchantInfoService = BLLContainer.Resolve <IBase_MerchantInfoService>(); if (base_MerchantInfoService.GetCount(p => !p.MerchID.Equals(merchId) && p.MerchAccount.Equals(merchAccount, StringComparison.OrdinalIgnoreCase)) > 0) { errMsg = "该商户账号名称已存在"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } var base_MerchantInfo = base_MerchantInfoService.GetModels(p => p.MerchID.Equals(merchId)).FirstOrDefault(); base_MerchantInfo.MerchType = Convert.ToInt32(merchType); base_MerchantInfo.MerchStatus = Convert.ToInt32(merchStatus); base_MerchantInfo.MerchAccount = merchAccount; base_MerchantInfo.MerchName = merchName; base_MerchantInfo.Mobil = mobil; base_MerchantInfo.WxOpenID = openId; base_MerchantInfo.WxUnionID = unionId; base_MerchantInfo.AllowCreateSub = !string.IsNullOrEmpty(allowCreateSub) ? Convert.ToInt32(allowCreateSub) : default(int?); base_MerchantInfo.AllowCreateCount = !string.IsNullOrEmpty(allowCreateCount) ? Convert.ToInt32(allowCreateCount) : default(int?); base_MerchantInfo.CreateUserID = createUserId; base_MerchantInfo.CreateType = (logType == (int)RoleType.XcUser || logType == (int)RoleType.XcAdmin) ? (int)CreateType.Xc : (logType == (int)RoleType.MerchUser ? (int)CreateType.Agent : 0); base_MerchantInfo.Comment = comment; base_MerchantInfo.MerchTag = Convert.ToInt32(merchTag); if (!base_MerchantInfoService.Update(base_MerchantInfo)) { errMsg = "修改商户信息失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); var base_UserInfo = base_UserInfoService.GetModels(p => p.OpenID.Equals(openId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (base_UserInfo == null) { base_UserInfo = new Base_UserInfo(); base_UserInfo.OpenID = openId; base_UserInfo.UserType = Convert.ToInt32(merchType); if (!base_UserInfoService.Add(base_UserInfo)) { errMsg = "添加商户负责人信息失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } if (merchFunction != null && merchFunction.Count() >= 0) { //先删除已有数据,后添加 var dbContext = DbContextFactory.CreateByModelNamespace(typeof(Base_MerchFunction).Namespace); var base_MerchFunctionList = dbContext.Set <Base_MerchFunction>().Where(p => p.MerchID.Equals(merchId, StringComparison.OrdinalIgnoreCase)).ToList(); foreach (var base_MerchFunction in base_MerchFunctionList) { dbContext.Entry(base_MerchFunction).State = EntityState.Deleted; } foreach (IDictionary <string, object> el in merchFunction) { if (el != null) { var dicPara = new Dictionary <string, object>(el, StringComparer.OrdinalIgnoreCase); string functionId = dicPara.ContainsKey("functionId") ? dicPara["functionId"].ToString() : string.Empty; string functionEn = dicPara.ContainsKey("functionEn") ? dicPara["functionEn"].ToString() : string.Empty; if (string.IsNullOrEmpty(functionId)) { errMsg = "功能编号不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!Utils.isNumber(functionId)) { errMsg = "功能编号不是Int类型"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!string.IsNullOrEmpty(functionEn) && !Utils.isNumber(functionEn)) { errMsg = "功能启停不是Int类型"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } var base_MerchFunction = new Base_MerchFunction(); base_MerchFunction.MerchID = merchId; base_MerchFunction.FunctionID = Convert.ToInt32(functionId); base_MerchFunction.FunctionEN = !string.IsNullOrEmpty(functionEn) ? Convert.ToInt32(functionEn) : default(int?); dbContext.Entry(base_MerchFunction).State = EntityState.Added; } else { errMsg = "提交数据包含空对象"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } if (dbContext.SaveChanges() < 0) { errMsg = "保存商户功能菜单信息失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } ts.Complete(); } catch (Exception ex) { errMsg = ex.Message; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } //更新缓存 MerchBusiness.Init(); return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn)); } catch (Exception e) { return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message)); } }