/// <summary> /// 删除数据 /// </summary> /// <param name="keyValue">主键</param> public void DeleteEntity(string keyValue) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { db.Delete <CrmOrderEntity>(t => t.F_OrderId.Equals(keyValue)); db.Delete <CrmOrderProductEntity>(t => t.F_OrderId.Equals(keyValue)); db.Commit(); } catch (Exception ex) { db.Rollback(); if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } }
/// <summary> /// 删除数据 /// </summary> /// <param name="keyValue">主键</param> public void DeleteEntity(string keyValue) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { db.Delete <CrmChanceEntity>(t => t.F_ChanceId == keyValue); db.Delete <CrmTrailRecordEntity>(t => t.F_ObjectId.Equals(keyValue)); db.Commit(); } catch (Exception ex) { db.Rollback(); if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } }
/// <summary> /// 删除功能 /// </summary> /// <param name="keyValue">主键</param> public void RemoveForm(string keyValue) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { int count = db.IQueryable <ModuleEntity>(t => t.ParentId == keyValue).Count(); if (count > 0) { throw new Exception("当前所选数据有子节点数据!"); } db.Delete <ModuleEntity>(keyValue); db.Delete <ModuleButtonEntity>(t => t.ModuleId.Equals(keyValue)); db.Delete <ModuleColumnEntity>(t => t.ModuleId.Equals(keyValue)); db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// /// </summary> /// <param name="year"></param> /// <param name="entities"></param> /// <exception cref="NotImplementedException"></exception> public void SaveData(string year, List <BpcSc003Entity> entities) { var deletedEntities = HQPASRepository().IQueryable().Where(t => t.ND == year).ToList(); IRepository db = new RepositoryFactory().HQPASRepository().BeginTrans(); try { int result = db.Delete(deletedEntities); foreach (var e in entities) { e.Create(); Thread.Sleep(5); } db.Insert(entities); db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 保存表单 /// </summary> /// <param name="entity">实体对象</param> /// <returns></returns> public void Save(MeetSubjectEntity entity) { var db = new RepositoryFactory().BaseRepository().BeginTrans(); try { var ck = db.IQueryable <AccountRuleEntity>(p => p.Standard == "班前一课" && p.IsOpen == 1).FirstOrDefault(); if (ck != null) { SafetyScoreService scoreService = new SafetyScoreService(); if (entity.State) { scoreService.AddScore(entity.TeachUserId, 7); } } db.Insert(entity); db.Commit(); } catch (Exception) { db.Rollback(); } }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveEntity(string keyValue, CrmChanceEntity entity) { try { if (!string.IsNullOrEmpty(keyValue)) { entity.Modify(keyValue); this.BaseRepository().Update(entity); } else { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { entity.Create(); db.Insert(entity); db.Commit(); } catch (Exception) { db.Rollback(); throw; } } } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } }
/// <summary> /// 保存表单(新增) /// </summary> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveEntity(CrmExpensesEntity entity) { CrmCashBalanceService crmCashBalanceService = new CrmCashBalanceService(); IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { //支出 entity.Create(); db.Insert(entity); //添加账户余额 crmCashBalanceService.AddBalance(db, new CrmCashBalanceEntity { F_ObjectId = entity.F_ExpensesId, F_ExecutionDate = entity.F_ExpensesDate, F_CashAccount = entity.F_ExpensesAccount, F_Expenses = entity.F_ExpensesPrice, F_Abstract = entity.F_ExpensesAbstract }); db.Commit(); } catch (Exception ex) { db.Rollback(); if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } }
/// <summary> /// 答题 /// </summary> /// <param name="titleid">表</param> /// <param name="sort">顺序</param> /// <param name="answer">答案</param> public void answerWork(string titleid, int sort, string answer) { var db = new RepositoryFactory().BaseRepository().BeginTrans(); try { var entity = db.FindEntity <HistoryUserAnswerEntity>(x => x.sort == sort && x.titleid == titleid); if (entity != null) { entity.answer = answer; db.Update(entity); } else { entity = new HistoryUserAnswerEntity(); entity.id = Guid.NewGuid().ToString(); entity.titleid = titleid; entity.sort = sort; entity.answer = answer; if (answer == "正确") { entity.istrue = true; } if (answer == "错误") { entity.istrue = false; } db.Insert(entity); } db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 修改证件信息 /// </summary> public void modifyUserCertificate(UserCertificateEntity entity) { var db = new RepositoryFactory().BaseRepository().BeginTrans(); var oldfiles = (from q in db.IQueryable <FileInfoEntity>() where q.RecId == entity.Id & q.Description != "成员证书二维码" select q).ToList(); try { var deletefiles = oldfiles.Except(entity.Files).ToList(); db.Delete(deletefiles); var newfiles = entity.Files.Except(oldfiles).ToList(); db.Insert(newfiles); entity.Files = null; db.Update(entity); db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 批量(新增) /// </summary> /// <param name="dtSource">实体对象</param> /// <returns></returns> public string BatchAddEntity(DataTable dtSource) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { for (int i = 0; i < dtSource.Rows.Count; i++) { TelphoneWashEntity entity = new TelphoneWashEntity(); string telphone = dtSource.Rows[i][0].ToString(); if (telphone.Length == 11) { var wash_Data = db.FindEntity <TelphoneWashEntity>(t => t.Telphone == telphone); if (wash_Data != null) { return(telphone + "重复导入!"); } entity.Telphone = telphone.ToString(); entity.Grade = telphone.Substring(3, 4); entity.Number = telphone.Substring(7); entity.DeleteMark = 0; entity.SellMark = 0; entity.IntentionMark = 0; entity.AssignMark = 0; entity.Create(); db.Insert(entity); } } db.Commit(); return("导入成功"); } catch (Exception ex) { return(ex.Message); } }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveForm(string keyValue, MeetSubjectEntity entity) { var db = new RepositoryFactory().BaseRepository().BeginTrans(); try { //添加安全积分 SafetyScoreService scoreService = new SafetyScoreService(); if (!string.IsNullOrEmpty(keyValue)) { var old = db.FindEntity <MeetSubjectEntity>(x => x.ID == keyValue); if (!old.State && entity.State) { var ck = db.IQueryable <AccountRuleEntity>(p => p.Standard == "班前一课" && p.IsOpen == 1).FirstOrDefault(); if (ck != null) { scoreService.AddScore(entity.TeachUserId, 7); } } db.Update(entity); } else { if (entity.State) { scoreService.AddScore(entity.TeachUserId, 7); } db.Insert(entity); } db.Commit(); } catch (Exception ex) { db.Rollback(); } }
/// <summary> /// 删除 /// </summary> /// <param name="keyvalue"></param> public void removeSweepAndItem(string keyvalue) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { var dataEntity = db.FindEntity<SweepEntity>(keyvalue); if (dataEntity != null) { db.Delete(dataEntity); var items = db.IQueryable<SweepItemEntity>(x => x.SweepId == keyvalue); if (items.Count() > 0) { db.Delete(items); } } db.Commit(); } catch (Exception e) { db.Rollback(); throw e; } }
/// <summary> /// 添加授权 /// </summary> /// <param name="objectType">权限分类-1角色2用户</param> /// <param name="objectId">对象Id</param> /// <param name="appModuleIds">功能Id</param> public void SaveAppAuthorize(int objectType, string objectId, string[] appModuleIds) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { db.Delete <AuthorizeEntity>(t => t.F_ObjectId == objectId); #region 功能 foreach (string item in appModuleIds) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.F_ObjectType = objectType; authorizeEntity.F_ObjectId = objectId; authorizeEntity.F_ItemType = 5; authorizeEntity.F_ItemId = item; db.Insert(authorizeEntity); } #endregion db.Commit(); } catch (Exception ex) { db.Rollback(); if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } }
public int SaveContentEntity(string keyValue, WFSchemeContentEntity modelentity) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); modelentity.SchemeVersion = DateTime.Now.ToString("yyyyMMddHHmmssffff"); try { if (string.IsNullOrEmpty(keyValue)) { modelentity.Create(); db.Insert <WFSchemeContentEntity>(modelentity); } else { var temp = schemeserver.GetEntity(keyValue); if (temp == null) { modelentity.Create(); db.Insert <WFSchemeContentEntity>(modelentity); } else { modelentity.Modify(keyValue); db.Update(modelentity); } } db.Commit(); return(1); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <param name="path">目录文件</param> /// <returns></returns> public void SaveForm(string keyValue, DesignationEntity entity) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { if (string.IsNullOrEmpty(keyValue)) { entity.Create(); db.Insert(entity); } else { entity.Modify(keyValue); db.Update(entity); } db.Commit(); } catch (Exception er) { db.Rollback(); throw; } }
/// <summary> /// /// </summary> /// <param name="entities"></param> public void AddRecords(List <BpcSP006Entity> entities) { IRepository db = new RepositoryFactory().HQPASRepository().BeginTrans(); try { foreach (var e in entities) { if (e.XH.IsEmpty()) { e.Create(); } } var result = db.Insert(entities); db.Commit(); } catch (Exception ex) { db.Rollback(); throw; } }
/// <summary> ///history 删除 /// </summary> public void RemoveFormHistory(string keyvalue) { var db = new RepositoryFactory().BaseRepository().BeginTrans(); try { var question = db.FindEntity <HistoryQuestionEntity>(keyvalue); if (question != null) { var answer = db.FindList <HistoryAnswerEntity>(x => x.questionid == keyvalue); foreach (var item in answer) { db.Delete(item); } db.Delete(question); } db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 删除 /// </summary> public void RemoveFormByOutId(string keyvalue) { var db = new RepositoryFactory().BaseRepository().BeginTrans(); try { var question = db.IQueryable <QuestionBankEntity>(x => x.outkeyvalue == keyvalue); if (question != null) { var answer = db.IQueryable <TheAnswerEntity>(x => x.questionid == keyvalue); foreach (var item in answer) { db.Delete(item); } db.Delete(question); } db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 删除 /// </summary> public void deleteEntity(string keyvalue) { var db = new RepositoryFactory().BaseRepository().BeginTrans(); try { var entity = db.FindEntity <CustomTemplateEntity>(keyvalue); if (entity != null) { entity.IsDel = true; entity.TitleContentList = null; entity.FormContentList = null; //db.Delete(entity); db.Update(entity); } db.Commit(); } catch (Exception ex) { db.Rollback(); throw; } }
/// <summary> ///人员状态 /// </summary> public void addState(UserWorkStateEntity entity) { var db = new RepositoryFactory().BaseRepository().BeginTrans(); try { if (string.IsNullOrEmpty(entity.Id)) { entity.Create(); db.Insert(entity); } else { db.Update(entity); } db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
public void updateEmergencyReportEvaluate(string EmergencyReportId, EmergencyReportEntity workEntity) { var db = new RepositoryFactory().BaseRepository().BeginTrans(); var query = db.FindEntity <EmergencyReportEntity>(EmergencyReportId); try { //var one = db.FindEntity<EmergencyReportEntity>(x => x.EmergencyReportId == EmergencyReportId); query.state = "1"; //if (!string.IsNullOrEmpty(workEntity.evaluationscore.ToString()) && workEntity.evaluationscore != 10) //{ // query.evaluationscore = workEntity.evaluationscore; //} if (!string.IsNullOrEmpty(workEntity.score.ToString()) && workEntity.score != 10) { query.score = workEntity.score; } query.evaluation = workEntity.evaluation; query.evaluationdate = DateTime.Now; query.evaluationuser = workEntity.evaluationuser; //query.score = query.score; //清理非实体的数据实例 query.EmergencyPersons = null; query.EmergencyReportSteps = null; query.File = null; query.MODIFYDATE = DateTime.Now; db.Update(query); db.Commit(); } catch (Exception ex) { db.Rollback(); throw ex; } }
/// <summary> /// 保存流程 /// </summary> /// <param name="entity">表单模板实体类</param> /// <param name="keyValue">主键</param> /// <returns></returns> public int SaveForm(string keyValue, WFSchemeInfoEntity entity, WFSchemeContentEntity modelentity, string[] shcemeAuthorizeData) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { if (string.IsNullOrEmpty(keyValue)) { entity.Create(); entity.SchemeVersion = DateTime.Now.ToString("yyyyMMddHHmmssffff"); db.Insert <WFSchemeInfoEntity>(entity); modelentity.Create(); modelentity.WFSchemeInfoId = entity.Id; modelentity.SchemeVersion = entity.SchemeVersion; db.Insert <WFSchemeContentEntity>(modelentity); } else { WFSchemeContentEntity modelentityold = schemeserver.GetEntity(keyValue, entity.SchemeVersion); if (modelentityold.SchemeContent != modelentity.SchemeContent) { if (modelentity.SchemeVersion == "cg") { modelentityold.SchemeContent = modelentity.SchemeContent; modelentityold.SchemeVersion = DateTime.Now.ToString("yyyyMMddHHmmssffff"); modelentity.SchemeVersion = modelentityold.SchemeVersion; db.Update <WFSchemeContentEntity>(modelentityold); } else { modelentity.Create(); modelentity.WFSchemeInfoId = keyValue; modelentity.SchemeVersion = DateTime.Now.ToString("yyyyMMddHHmmssffff"); db.Insert <WFSchemeContentEntity>(modelentity); } } else { modelentity.SchemeVersion = modelentityold.SchemeVersion; } entity.Modify(keyValue); entity.SchemeVersion = modelentity.SchemeVersion; db.Update <WFSchemeInfoEntity>(entity); } db.Delete <WFSchemeInfoAuthorizeEntity>(entity.Id, "SchemeInfoId"); foreach (string item in shcemeAuthorizeData) { if (item != "") { WFSchemeInfoAuthorizeEntity _authorizeEntity = new WFSchemeInfoAuthorizeEntity(); _authorizeEntity.Create(); _authorizeEntity.SchemeInfoId = entity.Id; _authorizeEntity.ObjectId = item; db.Insert(_authorizeEntity); } } db.Commit(); return(1); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 批量(新增) /// </summary> /// <param name="dtSource">实体对象</param> /// <returns></returns> public string BatchAddEntity(DataTable dtSource) { int rowsCount = dtSource.Rows.Count; //判断号码上限 string greaterMsg = IsGreater(rowsCount); IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); if (!string.IsNullOrEmpty(greaterMsg)) { return(greaterMsg); } for (int i = 0; i < rowsCount; i++) { try { string telphone = dtSource.Rows[i][0].ToString(); if (telphone.Length == 11) { var liang_Data = db.FindEntity <TelphoneLiangEntity>(t => t.Telphone == telphone && t.DeleteMark != 1);//删除过的可以再次导入 if (liang_Data != null) { return(telphone + "重复导入!"); } //根据前7位确定城市和运营商 string Number7 = telphone.Substring(0, 7); string City = "", CityId = "", Operator = ""; var TelphoneData = db.FindEntity <TelphoneDataEntity>(t => t.Number7 == Number7); if (TelphoneData != null) { City = TelphoneData.City.Replace("市", ""); CityId = TelphoneData.CityId; Operator = TelphoneData.Operate; } else { return("号段不存在:" + Number7); } //价格 if (string.IsNullOrEmpty(dtSource.Rows[i][1].ToString())) { return(telphone + "价格为空"); } decimal Price = Convert.ToDecimal(dtSource.Rows[i][1].ToString()); //成本价 if (string.IsNullOrEmpty(dtSource.Rows[i][2].ToString())) { return(telphone + "成本价为空"); } decimal MinPrice = Convert.ToDecimal(dtSource.Rows[i][2].ToString()); //利润 decimal ChaPrice = Price - MinPrice; //类别 if (string.IsNullOrEmpty(dtSource.Rows[i][3].ToString())) { return(telphone + "类别为空"); } string itemName = dtSource.Rows[i][3].ToString(); string itemNCode = ""; var DataItemDetail = db.FindEntity <DataItemDetailEntity>(t => t.ItemName == itemName); if (DataItemDetail != null) { itemNCode = DataItemDetail.ItemValue; } else { return("类型不存在:" + itemName + ",请在数据字典里维护此类型。"); } //套餐 string Package = dtSource.Rows[i][4].ToString(); //状态 string existStr = dtSource.Rows[i][5].ToString(); if (string.IsNullOrEmpty(existStr)) { return(telphone + "现卡/代售/秒杀状态为空"); } if (existStr != "秒杀" && existStr != "现卡" && existStr != "预售") { return(telphone + "现卡/代售/秒杀状态填写错误"); } int existMark = 0; if (existStr == "秒杀") { existMark = 2; } else if (existStr == "现卡") { existMark = 1; } else { existMark = 0; } //添加靓号 TelphoneLiangEntity entity = new TelphoneLiangEntity() { Telphone = telphone, Price = Price, MinPrice = MinPrice, ChaPrice = ChaPrice, City = City, CityId = CityId, Operator = Operator, Grade = itemNCode, Package = Package, ExistMark = existMark, SellMark = 0, DeleteMark = 0, OrganizeId = OperatorProvider.Provider.Current().CompanyId, }; entity.Create(); db.Insert(entity); } } catch (Exception ex) { return(ex.Message); } } db.Commit(); return("导入成功"); }
/// <summary> /// 添加授权 /// </summary> /// <param name="authorizeType">权限分类</param> /// <param name="objectId">对象Id</param> /// <param name="moduleIds">功能Id</param> /// <param name="moduleButtonIds">按钮Id</param> /// <param name="moduleColumnIds">视图Id</param> /// <param name="authorizeDataList">数据权限</param> public void SaveAuthorize(AuthorizeTypeEnum authorizeType, string objectId, string[] moduleIds, string[] moduleButtonIds, string[] moduleColumnIds, IEnumerable <AuthorizeDataEntity> authorizeDataList) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { db.Delete <AuthorizeEntity>(t => t.ObjectId == objectId); #region 功能 int SortCode = 1; foreach (string item in moduleIds) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = (int)authorizeType; authorizeEntity.ObjectId = objectId; authorizeEntity.ItemType = 1; authorizeEntity.ItemId = item; authorizeEntity.SortCode = SortCode++; db.Insert(authorizeEntity); } #endregion #region 钮 SortCode = 1; foreach (string item in moduleButtonIds) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = (int)authorizeType; authorizeEntity.ObjectId = objectId; authorizeEntity.ItemType = 2; authorizeEntity.ItemId = item; authorizeEntity.SortCode = SortCode++; db.Insert(authorizeEntity); } #endregion #region 视图 SortCode = 1; foreach (string item in moduleColumnIds) { AuthorizeEntity authorizeEntity = new AuthorizeEntity(); authorizeEntity.Create(); authorizeEntity.Category = (int)authorizeType; authorizeEntity.ObjectId = objectId; authorizeEntity.ItemType = 3; authorizeEntity.ItemId = item; authorizeEntity.SortCode = SortCode++; db.Insert(authorizeEntity); } #endregion #region 数据权限 SortCode = 1; db.Delete <AuthorizeDataEntity>(objectId, "ObjectId"); int index = 0; foreach (AuthorizeDataEntity authorizeDataEntity in authorizeDataList) { authorizeDataEntity.Create(); authorizeDataEntity.Category = (int)authorizeType; authorizeDataEntity.ObjectId = objectId; // authorizeDataEntity.Module = "Department"; authorizeDataEntity.SortCode = SortCode++; db.Insert(authorizeDataEntity); index++; } #endregion db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 保存或修改部门班次信息 /// </summary> public void WorkSetSave(List <WorkOrderEntity> data, List <WorkGroupSetEntity> group, List <WorkTimeSortEntity> timeList) { var db = new RepositoryFactory().BaseRepository().BeginTrans(); try { var addTime = new List <WorkTimeSortEntity>(); #region 需要清理的数据 var delGroup = new List <WorkGroupSetEntity>(); var delOrder = new List <WorkOrderEntity>(); //排班数据 var delTime = new List <WorkTimeSortEntity>(); var UpdateTime = new List <WorkTimeSortEntity>(); foreach (var item in timeList) { if (item.datatype == "add") { addTime.Add(item); } else if (item.datatype == "del") { delTime.Add(item); } else { UpdateTime.Add(item); } item.datatype = null; } //根据班组获取原有排班设置清理 var bookmarks = string.Empty; foreach (var item in group) { var getGroup = (from q in db.IQueryable <WorkGroupSetEntity>() where q.departmentid == item.departmentid select q).ToList(); //存在原有数据 if (getGroup.Count() == 1) { bookmarks = getGroup[0].bookmarks; var allGroup = (from q in db.IQueryable <WorkGroupSetEntity>() where q.bookmarks == bookmarks select q).ToList(); foreach (var groups in allGroup) { if (delGroup.IndexOf(groups) < 0) { delGroup.Add(groups); } } } } var allOrder = (from q in db.IQueryable <WorkOrderEntity>() where q.bookmarks == bookmarks select q).ToList(); foreach (var order in allOrder) { if (delOrder.IndexOf(order) < 0) { delOrder.Add(order); } } if (delTime.Count > 0) { db.Delete(delTime); } if (delGroup.Count > 0) { db.Delete(delGroup); } if (delOrder.Count > 0) { db.Delete(delOrder); } if (UpdateTime.Count > 0) { db.Update(UpdateTime); } #endregion if (data.Count > 0) { db.Insert(data); } if (group.Count > 0) { db.Insert(group); } if (group.Count > 0) { db.Insert(addTime); } db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 保存用户表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="userEntity">用户实体</param> /// <returns></returns> public string SaveForm(string keyValue, UserEntity userEntity) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { #region 基本信息 if (!string.IsNullOrEmpty(keyValue)) { userEntity.Modify(keyValue); userEntity.Password = null; db.Update(userEntity); } else { userEntity.Create(); keyValue = userEntity.UserId; userEntity.Secretkey = Md5Helper.MD5(CommonHelper.CreateNo(), 16).ToLower(); userEntity.Password = Md5Helper.MD5(DESEncrypt.Encrypt(Md5Helper.MD5(userEntity.Password, 32).ToLower(), userEntity.Secretkey).ToLower(), 32).ToLower(); db.Insert(userEntity); } #endregion #region 默认添加 角色、岗位、职位 db.Delete <UserRelationEntity>(t => t.IsDefault == 1 && t.UserId == userEntity.UserId); List <UserRelationEntity> userRelationEntitys = new List <UserRelationEntity>(); //角色 if (!string.IsNullOrEmpty(userEntity.RoleId)) { userRelationEntitys.Add(new UserRelationEntity { Category = 2, UserRelationId = Guid.NewGuid().ToString(), UserId = userEntity.UserId, ObjectId = userEntity.RoleId, CreateDate = DateTime.Now, CreateUserId = OperatorProvider.Provider.Current().UserId, CreateUserName = OperatorProvider.Provider.Current().UserName, IsDefault = 1, }); } //岗位 if (!string.IsNullOrEmpty(userEntity.DutyId)) { userRelationEntitys.Add(new UserRelationEntity { Category = 3, UserRelationId = Guid.NewGuid().ToString(), UserId = userEntity.UserId, ObjectId = userEntity.DutyId, CreateDate = DateTime.Now, CreateUserId = OperatorProvider.Provider.Current().UserId, CreateUserName = OperatorProvider.Provider.Current().UserName, IsDefault = 1, }); } //职位 if (!string.IsNullOrEmpty(userEntity.PostId)) { userRelationEntitys.Add(new UserRelationEntity { Category = 4, UserRelationId = Guid.NewGuid().ToString(), UserId = userEntity.UserId, ObjectId = userEntity.PostId, CreateDate = DateTime.Now, CreateUserId = OperatorProvider.Provider.Current().UserId, CreateUserName = OperatorProvider.Provider.Current().UserName, IsDefault = 1, }); } db.Insert(userRelationEntitys); #endregion db.Commit(); return(keyValue); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 保存模板信息 /// </summary> /// <param name="keyValue">主键</param> /// <param name="infoEntity">模板基础信息</param> /// <param name="schemeEntity">模板信息</param> /// <param name="authList">模板权限信息</param> public void SaveEntity(string keyValue, NWFSchemeInfoEntity infoEntity, NWFSchemeEntity schemeEntity, List <NWFSchemeAuthEntity> authList) { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); try { if (string.IsNullOrEmpty(keyValue)) { infoEntity.Create(); } else { infoEntity.Modify(keyValue); } #region 模板信息 if (schemeEntity != null) { schemeEntity.F_SchemeInfoId = infoEntity.F_Id; schemeEntity.Create(); db.Insert(schemeEntity); infoEntity.F_SchemeId = schemeEntity.F_Id; } #endregion #region 模板基础信息 if (!string.IsNullOrEmpty(keyValue)) { db.Update(infoEntity); } else { db.Insert(infoEntity); } #endregion #region 流程模板权限信息 string schemeInfoId = infoEntity.F_Id; db.Delete <NWFSchemeAuthEntity>(t => t.F_SchemeInfoId == schemeInfoId); foreach (var item in authList) { item.Create(); item.F_SchemeInfoId = schemeInfoId; db.Insert(item); } #endregion db.Commit(); } catch (Exception ex) { db.Rollback(); if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } }
/// <summary> /// 登录 /// </summary> /// <returns></returns> public ShopEntity DoLogin(LoginViewModel loginModel, string accessToken) { ShopEntity shop = null; var db = new RepositoryFactory().BaseRepository().BeginTrans(); try { var isOk = CheckLoginModel(loginModel, accessToken); LogUtil.Info(string.Format("登录参数验证{0}", isOk ? "通过" : "失败")); if (isOk) { var dbNow = TimeUtil.Now; var mobile = loginModel != null?loginModel.ShopAccount.Trim() : string.Empty; var vCode = loginModel != null?loginModel.VerifyCode.Trim() : string.Empty; if (!string.IsNullOrWhiteSpace(mobile)) { SingleInstance <VerifyCodeBLL> .Instance.UpdateVerifyCode(ConfigUtil.SystemAppSign, vCode, mobile); } LogUtil.Info(string.Format("mobile:{0},vCode:{1},accessToken:{2}", mobile, vCode, accessToken)); shop = GetCurrentInfo(mobile, accessToken, false); if (shop == null) { if (!string.IsNullOrWhiteSpace(mobile) && !string.IsNullOrWhiteSpace(vCode)) { //用户不存在,自动注册 shop = new ShopEntity(); shop.MerchantId = StringUtil.UniqueStr(); shop.ShopAccount = mobile; shop.LastLoginIp = NetUtil.Ip; shop.LastLoginTime = dbNow; shop.AccessToken = StringUtil.UniqueStr().ToUpper(); shop.ExpiresTime = dbNow.AddHours(12 * 30); shop.CreateDate = dbNow; shop.CreateUserId = mobile; shop.EnabledFlag = EnabledFlagType.Valid.GetHashCode(); shop.DeleteFlag = DeleteFlagType.Valid.GetHashCode(); service.InsertEntity(shop); } else { throw new AuthenticationException("会话超时,请重新登录!"); } } else { //用户存在更新信息及是否更新访问令牌 shop.LastLoginIp = NetUtil.Ip; shop.LastLoginTime = dbNow; if (!string.IsNullOrWhiteSpace(mobile) && !string.IsNullOrWhiteSpace(vCode)) { //手动登录才更新Token shop.AccessToken = StringUtil.UniqueStr().ToUpper(); shop.ExpiresTime = dbNow.AddHours(12 * 30); } service.UpdateEntity(shop); //校验用户信息 CheckShopStatus(shop, OperateType.DoLogin); } //更新微信用户门店关联信息 if (loginModel != null && !string.IsNullOrWhiteSpace(loginModel.OpenId)) { SingleInstance <WeChatBLL> .Instance.UpdateWxUserInfo(shop.ShopId, loginModel.OpenId, EnumWeChatType.Client.GetHashCode()); } db.Commit(); } } catch (AuthenticationException ex) { db.Rollback(); throw new AuthenticationException(ex.Message); } catch (Exception ex) { db.Rollback(); LogUtil.Error(string.Format("登录失败,参考消息:{0}", ex.StackTrace)); throw new MessageException(ex.Message); } return(shop); }
/// <summary> /// 更新绑定手机号 /// </summary> /// <param name="appSign"></param> /// <param name="curUser"></param> /// <param name="bindModel"></param> public void BindMobile(string appSign, ShopEntity curUser, BindMobileViewModel bindModel) { var db = new RepositoryFactory().BaseRepository().BeginTrans(); try { // 校验参数 if (bindModel == null) { throw new MessageException("更新参数不可为空!"); } if (bindModel.NewMobile == bindModel.Mobile) { throw new MessageException("新手机号与原手机号相同!"); } if (bindModel.Mobile != curUser.ShopAccount) { throw new MessageException("原手机号不正确请核对!"); } var shop = GetShopByMobile(bindModel.NewMobile, OperateType.GetInfo); if (shop != null) { //1.校验是否存在订单 var isExistsOrder = SingleInstance <OrderBLL> .Instance.CheckShopIsExistsOrder(shop.ShopId); if (isExistsOrder) { throw new MessageException("新手机账号下已有订单,请联系客服!"); } //2.校验是否关联打印机 var isBindPrinter = SingleInstance <PrinterBLL> .Instance.CheckShopIsBindPrinter(shop.ShopId); if (isBindPrinter) { throw new MessageException("新手机账号下已绑定打印机,请先解除!"); } //3.校验是否授权第三方平台 var isAuth = SingleInstance <PlatformBLL> .Instance.CheckShopIsAuhtPlatform(shop.ShopId); if (isAuth) { throw new MessageException("新手机账号下已有第三方平台授权,请先取消!"); } //throw new MessageException("新手机号已注册!"); } // 更新验证码 SingleInstance <VerifyCodeBLL> .Instance.UpdateVerifyCode(appSign, bindModel.VerifyCode, bindModel.NewMobile); if (shop != null) { // 4.删除新手机号对应门店账户信息 service.Remove(shop.ShopId); } // 5.更新手机号 curUser.ShopAccount = bindModel.NewMobile; service.UpdateEntity(curUser); db.Commit(); } catch (Exception ex) { db.Rollback(); LogUtil.Error(ex.StackTrace); throw new MessageException(ex.Message); } }
public void SaveFormWork(string keyValue, EmergencyWorkEntity workEntity) { var db = new RepositoryFactory().BaseRepository().BeginTrans(); try { var user = db.FindEntity <DepartmentEntity>(x => x.DepartmentId == workEntity.ToCompileDeptId); var dept = db.FindEntity <UserEntity>(x => x.UserId == workEntity.ToCompileUserid); if (user != null) { workEntity.ToCompileDept = user.FullName; } if (dept != null) { workEntity.ToCompileUser = dept.RealName; } if (string.IsNullOrEmpty(keyValue) || keyValue == "undefined") { workEntity.EmergencyId = Guid.NewGuid().ToString(); workEntity.CREATEDATE = DateTime.Now; //workEntity.CREATEUSERID = OperatorProvider.Provider.Current().UserId; //workEntity.CREATEUSERNAME = OperatorProvider.Provider.Current().UserName; string[] array = workEntity.ImplementStep.Split(new char[] { '\r', '\n' }); var esList = new List <EmergencyStepsEntity>(); int i = 0; foreach (string str in array) { if (str.Trim() != "" && !string.IsNullOrEmpty(str)) { EmergencyStepsEntity esEntity = new EmergencyStepsEntity(); esEntity.EmergencyStepsId = Guid.NewGuid().ToString(); esEntity.EmergencyId = workEntity.EmergencyId; esEntity.EmergencyContext = str; esEntity.EmergencySort = i; esEntity.CREATEDATE = DateTime.Now; //esEntity.CREATEUSERID = OperatorProvider.Provider.Current().UserId; //esEntity.CREATEUSERNAME = OperatorProvider.Provider.Current().UserName; esList.Add(esEntity); i++; } } db.Insert <EmergencyStepsEntity>(esList); db.Insert(workEntity); db.Commit(); } else { var entity1 = GetWorkEntity(keyValue); //entity1.Name = entity.Name; entity1.Name = workEntity.Name; entity1.EmergencyType = workEntity.EmergencyType; entity1.ToCompileUser = workEntity.ToCompileUser; entity1.ToCompileUserid = workEntity.ToCompileUserid; entity1.ToCompileDeptId = workEntity.ToCompileDeptId; entity1.ToCompileDept = workEntity.ToCompileDept; entity1.Attachment = workEntity.Attachment; entity1.Purpose = workEntity.Purpose; entity1.RehearseDate = workEntity.RehearseDate; entity1.RehearsePlace = workEntity.RehearsePlace; entity1.RehearseType = workEntity.RehearseType; entity1.RehearseScenario = workEntity.RehearseScenario; entity1.RehearseName = workEntity.RehearseName; //entity1.Name = workEntity.Name; entity1.MainPoints = workEntity.MainPoints; entity1.MODIFYDATE = DateTime.Now; //entity1.MODIFYUSERID = OperatorProvider.Provider.Current().UserId; //entity1.MODIFYUSERNAME = OperatorProvider.Provider.Current().UserName; entity1.ImplementStep = null; //添加实施步骤 db.Delete <EmergencyStepsEntity>(x => x.EmergencyId.Equals(keyValue)); string[] array = workEntity.ImplementStep.Split(new char[] { '\r', '\n' }); var esList = new List <EmergencyStepsEntity>(); int i = 0; foreach (string str in array) { if (str.Trim() != "" && !string.IsNullOrEmpty(str)) { EmergencyStepsEntity esEntity = new EmergencyStepsEntity(); esEntity.EmergencyStepsId = Guid.NewGuid().ToString(); esEntity.EmergencyId = keyValue; esEntity.EmergencyContext = str; esEntity.EmergencySort = i; esEntity.CREATEDATE = DateTime.Now; //esEntity.CREATEUSERID = OperatorProvider.Provider.Current().UserId; //esEntity.CREATEUSERNAME = OperatorProvider.Provider.Current().UserName; esList.Add(esEntity); i++; } } db.Insert <EmergencyStepsEntity>(esList); db.Update <EmergencyWorkEntity>(entity1); db.Commit(); } } catch (Exception) { db.Rollback(); throw; } }