public virtual async Task <WC_MessageResponseModel> GetByIdAsync(object id) { if (IsExists(id)) { WC_MessageResponse entity = await m_Rep.GetByIdAsync(id); WC_MessageResponseModel model = new WC_MessageResponseModel(); model.Id = entity.Id; model.OfficalAccountId = entity.OfficalAccountId; model.MessageRule = entity.MessageRule; model.Category = entity.Category; model.MatchKey = entity.MatchKey; model.TextContent = entity.TextContent; model.ImgTextContext = entity.ImgTextContext; model.ImgTextUrl = entity.ImgTextUrl; model.ImgTextLink = entity.ImgTextLink; model.MeidaUrl = entity.MeidaUrl; model.MeidaLink = entity.MeidaLink; model.Enable = entity.Enable; model.IsDefault = entity.IsDefault; model.Remark = entity.Remark; model.Sort = entity.Sort; model.CreateTime = entity.CreateTime; model.CreateBy = entity.CreateBy; model.ModifyTime = entity.ModifyTime; model.ModifyBy = entity.ModifyBy; return(model); } else { return(null); } }
public WC_MessageResponse GetById(string id) { if (m_Rep.IsContains(a => a.KEY_Id == id)) { WC_MessageResponse entity = m_Rep.GetById(id); WC_MessageResponse model = new WC_MessageResponse(); model.Id = entity.Id; model.OfficalAccountId = entity.OfficalAccountId; model.MessageRule = entity.MessageRule; model.Category = entity.Category; model.MatchKey = entity.MatchKey; model.TextContent = entity.TextContent; model.ImgTextContext = entity.ImgTextContext; model.ImgTextUrl = entity.ImgTextUrl; model.ImgTextLink = entity.ImgTextLink; model.MeidaUrl = entity.MeidaUrl; model.MeidaLink = entity.MeidaLink; model.Enable = entity.Enable; model.IsDefault = entity.IsDefault; model.Remark = entity.Remark; model.Sort = entity.Sort; model.CreateTime = entity.CreateTime; model.CreateBy = entity.CreateBy; model.ModifyTime = entity.ModifyTime; model.ModifyBy = entity.ModifyBy; return(model); } else { return(null); } }
public bool PostData(WC_MessageResponse model) { //如果所有开关都关掉,证明不启用回复 if (model.Category == null) { return(true); } //全部设置为不默认 m_Rep.ExecuteSqlCommand(string.Format("update [dbo].[WC_MessageResponse] set IsDefault=0 where OfficalAccountId ='{0}' and MessageRule={1}", ResultHelper.Formatstr(model.OfficalAccountId), model.MessageRule)); //默认回复和订阅回复,且不是图文另外处理,因为他们有3种模式,但是只有一个是默认的 if (model.Category != WeChatReplyCategory.Image.ToString() && (model.MessageRule == WeChatRequestRuleEnum.Default.ToString() || model.MessageRule == WeChatRequestRuleEnum.Subscriber.ToString())) { //查看数据库是否存在数据 var entity = m_Rep.DbContext.WC_MessageResponse.Where(p => p.OfficalAccountId == model.OfficalAccountId && p.MessageRule == model.MessageRule && p.Category == model.Category).FirstOrDefault(); if (entity != null) { //删除原来的 m_Rep.DbContext.WC_MessageResponse.Remove(entity); } } //全部设置为默认 m_Rep.ExecuteSqlCommand(string.Format("update [dbo].[WC_MessageResponse] set IsDefault=1 where OfficalAccountId ='{0}' and MessageRule={1} and Category={2}", ResultHelper.Formatstr(model.OfficalAccountId), model.MessageRule, model.Category)); //修改 if (m_Rep.IsContains(a => a.KEY_Id == model.KEY_Id)) { m_Rep.DbContext.Entry <WC_MessageResponse>(model).State = EntityState.Modified; return(m_Rep.Update(model)); } else { return(m_Rep.Create(model)); } }
////[SupportFilter(ActionName = "Edit")] public JsonResult PostData(WC_MessageResponse model) { WC_OfficalAccounts accountModel = account_BLL.GetCurrentAccount(); //if (string.IsNullOrEmpty(model.Id)) //{ // model.Id = ResultHelper.NewId; //} model.CreateBy = GetUserId(); model.CreateTime = ResultHelper.NowTime.ToString("yyyy-MM-dd HH:mm:ss"); model.ModifyBy = GetUserId(); model.ModifyTime = ResultHelper.NowTime.ToString("yyyy-MM-dd HH:mm:ss"); model.OfficalAccountId = accountModel.Id.ToString(); model.Enable = "true"; model.IsDefault = "true"; if (m_BLL.PostData(ref errors, model)) { LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",OfficalAccountId" + model.OfficalAccountId, "成功", "保存", "WC_MessageResponse"); return(Json(JsonHandler.CreateMessage(1, Resource.SaveSucceed))); } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",OfficalAccountId" + model.OfficalAccountId + "," + ErrorCol, "失败", "保存", "WC_MessageResponse"); return(Json(JsonHandler.CreateMessage(0, Resource.SaveFail + ErrorCol))); } }
public int Create(WC_MessageResponse entity) { using (AppsDBEntities db = new AppsDBEntities()) { db.WC_MessageResponse.Add(entity); return(db.SaveChanges()); } }
public int Edit(WC_MessageResponse entity) { using (AppsDBEntities db = new AppsDBEntities()) { db.WC_MessageResponse.Attach(entity); db.Entry <WC_MessageResponse>(entity).State = EntityState.Modified; //db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); return(db.SaveChanges()); } }
public bool IsExist(string id) { using (AppsDBEntities db = new AppsDBEntities()) { WC_MessageResponse entity = GetById(id); if (entity != null) { return(true); } return(false); } }
public int Delete(string id) { using (AppsDBEntities db = new AppsDBEntities()) { WC_MessageResponse entity = db.WC_MessageResponse.SingleOrDefault(a => a.Id == id); if (entity != null) { db.WC_MessageResponse.Remove(entity); } return(db.SaveChanges()); } }
public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(WC_MessageResponseModel model) { ValidationErrors errors = new ValidationErrors(); try { WC_MessageResponse entity = await m_Rep.GetByIdAsync(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(new Tuple <ValidationErrors, bool>(errors, false)); } entity = new WC_MessageResponse(); entity.Id = model.Id; entity.OfficalAccountId = model.OfficalAccountId; entity.MessageRule = model.MessageRule; entity.Category = model.Category; entity.MatchKey = model.MatchKey; entity.TextContent = model.TextContent; entity.ImgTextContext = model.ImgTextContext; entity.ImgTextUrl = model.ImgTextUrl; entity.ImgTextLink = model.ImgTextLink; entity.MeidaUrl = model.MeidaUrl; entity.MeidaLink = model.MeidaLink; entity.Enable = model.Enable; entity.IsDefault = model.IsDefault; entity.Remark = model.Remark; entity.Sort = model.Sort; entity.CreateTime = model.CreateTime; entity.CreateBy = model.CreateBy; entity.ModifyTime = model.ModifyTime; entity.ModifyBy = model.ModifyBy; if (await m_Rep.CreateAsync(entity)) { return(new Tuple <ValidationErrors, bool>(errors, true)); } else { errors.Add(Resource.InsertFail); return(new Tuple <ValidationErrors, bool>(errors, false)); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(new Tuple <ValidationErrors, bool>(errors, false)); } }
public virtual bool Edit(ref ValidationErrors errors, WC_MessageResponseModel model) { try { WC_MessageResponse entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return(false); } entity.Id = model.Id; entity.OfficalAccountId = model.OfficalAccountId; entity.MessageRule = model.MessageRule; entity.Category = model.Category; entity.MatchKey = model.MatchKey; entity.TextContent = model.TextContent; entity.ImgTextContext = model.ImgTextContext; entity.ImgTextUrl = model.ImgTextUrl; entity.ImgTextLink = model.ImgTextLink; entity.MeidaUrl = model.MeidaUrl; entity.MeidaLink = model.MeidaLink; entity.Enable = model.Enable; entity.IsDefault = model.IsDefault; entity.Remark = model.Remark; entity.Sort = model.Sort; entity.CreateTime = model.CreateTime; entity.CreateBy = model.CreateBy; entity.ModifyTime = model.ModifyTime; entity.ModifyBy = model.ModifyBy; if (m_Rep.Edit(entity)) { return(true); } else { errors.Add(Resource.NoDataChange); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public bool Create(ref ValidationErrors errors, WC_MessageResponseModel model) { try { WC_MessageResponse entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Suggestion.PrimaryRepeat); return(false); } entity = new WC_MessageResponse(); entity.Category = model.Category; entity.CreateBy = model.CreateBy; entity.CreateTime = model.CreateTime; entity.Enable = model.Enable; entity.Id = model.Id; entity.ImgTextContext = model.ImgTextContext; entity.ImgTextLink = model.ImgTextLink; entity.ImgTextUrl = model.ImgTextUrl; entity.IsDefault = model.IsDefault; entity.MatchKey = model.MatchKey; entity.MeidaLink = model.MeidaLink; entity.MeidaUrl = model.MeidaUrl; entity.MessageRule = model.MessageRule; entity.ModifyBy = model.ModifyBy; entity.ModifyTime = model.ModifyTime; entity.OfficalAccountId = model.OfficalAccountId; entity.Remark = model.Remark; entity.Sort = model.Sort; entity.TextContent = model.TextContent; if (m_Rep.Create(entity) == 1) { return(true); } else { errors.Add(Suggestion.InsertFail); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public bool PostData(ref ValidationErrors errors, WC_MessageResponse model) { try { WC_MessageResponse entity = new WC_MessageResponse(); if (m_Rep.IsContains(a => a.KEY_Id == model.KEY_Id)) { entity = m_Rep.Find(a => a.KEY_Id == model.KEY_Id); } entity.Id = model.Id; entity.OfficalAccountId = model.OfficalAccountId; entity.MessageRule = model.MessageRule; entity.Category = model.Category; entity.MatchKey = model.MatchKey; entity.TextContent = model.TextContent; entity.ImgTextContext = model.ImgTextContext; entity.ImgTextUrl = model.ImgTextUrl; entity.ImgTextLink = model.ImgTextLink; entity.MeidaUrl = model.MeidaUrl; entity.Enable = model.Enable; entity.IsDefault = model.IsDefault; entity.Remark = model.Remark; entity.CreateTime = model.CreateTime; entity.CreateBy = model.CreateBy; entity.Sort = model.Sort; entity.ModifyTime = model.ModifyTime; entity.ModifyBy = model.ModifyBy; if (m_Rep.Create(entity)) { return(true); } else { errors.Add(Resource.NoDataChange); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
/// <summary> /// 获取消息自动回复的信息 /// </summary> /// <param name="officalAccountId">请求的公众号</param> /// <param name="matchKey">关键字</param> /// <returns></returns> public WC_MessageResponseModel GetAutoReplyMessage(string officalAccountId, string matchKey) { IQueryable <WC_MessageResponse> queryable = m_Rep.GetList(); //从数据库获取一条记录来回复,完全匹配 WC_MessageResponse entity = queryable.Where(a => a.OfficalAccountId == officalAccountId && a.MessageRule != (int)WeChatRequestRuleEnum.Default && a.MessageRule != (int)WeChatRequestRuleEnum.Subscriber && a.MessageRule != (int)WeChatRequestRuleEnum.Location && a.Category == (int)WeChatReplyCategory.Equal && a.MatchKey == matchKey ).FirstOrDefault(); //如果没有符合要求的回复,那么使用包含匹配 if (entity == null) { entity = queryable.Where(a => a.OfficalAccountId == officalAccountId && a.MessageRule != (int)WeChatRequestRuleEnum.Default && a.MessageRule != (int)WeChatRequestRuleEnum.Subscriber && a.MessageRule != (int)WeChatRequestRuleEnum.Location && a.Category == (int)WeChatReplyCategory.Contain && a.MatchKey.Contains(matchKey) ).FirstOrDefault(); } //如果都没有,使用默认回复 if (entity == null) { entity = queryable.Where(a => a.OfficalAccountId == officalAccountId && a.MessageRule == (int)WeChatRequestRuleEnum.Default && a.IsDefault).FirstOrDefault(); } if (entity != null) { return(this.GetById(entity.Id)); } else { return(null); } }
public bool PostData(WC_MessageResponse model) { //如果所有开关都关掉,证明不启用回复 if (model.Category == null) { return(true); } //全部设置为不默认 ExecuteSqlCommand(string.Format("Update [dbo].[WC_MessageResponse] set IsDefault=0 where OfficalAccountId='{0}' and MessageRule={1}", model.OfficalAccountId, model.MessageRule)); //默认回复和订阅回复,且不是图文另外处理,因为他们有三种模式,但是只有一个是默认的 if (model.Category != (int)WeChatReplyCategory.Image && (model.MessageRule == (int)WeChatRequestRuleEnum.Default || model.MessageRule == (int)WeChatRequestRuleEnum.Subscriber)) { //查看数据库是否存在数据 using (AppsDBEntities db = new AppsDBEntities()) { var entity = db.WC_MessageResponse.Where(p => p.OfficalAccountId == model.OfficalAccountId && p.MessageRule == model.MessageRule && p.Category == model.Category).FirstOrDefault(); if (entity != null) { //删除原来的 db.WC_MessageResponse.Remove(entity); } } } //全部设置为默认 ExecuteSqlCommand(string.Format("Update [dbo].[WC_MessageResponse] set IsDefault=1 where OfficalAccountId='{0}' and MessageRule={1} and Category={2}", model.OfficalAccountId, model.MessageRule, model.Category)); //修改 if (IsExist(model.Id)) { using (AppsDBEntities db = new AppsDBEntities()) { db.Entry <WC_MessageResponse>(model).State = EntityState.Modified; return(Edit(model) == 1 ? true : false); } } else { return(Create(model) == 1 ? true : false); } }
/// <summary> /// 保存数据 /// </summary> public virtual void SaveImportData(IEnumerable <WC_MessageResponseModel> list) { try { using (DBContainer db = new DBContainer()) { foreach (var model in list) { WC_MessageResponse entity = new WC_MessageResponse(); entity.Id = ResultHelper.NewId; entity.OfficalAccountId = model.OfficalAccountId; entity.MessageRule = model.MessageRule; entity.Category = model.Category; entity.MatchKey = model.MatchKey; entity.TextContent = model.TextContent; entity.ImgTextContext = model.ImgTextContext; entity.ImgTextUrl = model.ImgTextUrl; entity.ImgTextLink = model.ImgTextLink; entity.MeidaUrl = model.MeidaUrl; entity.MeidaLink = model.MeidaLink; entity.Enable = model.Enable; entity.IsDefault = model.IsDefault; entity.Remark = model.Remark; entity.Sort = model.Sort; entity.CreateTime = ResultHelper.NowTime; entity.CreateBy = model.CreateBy; entity.ModifyTime = model.ModifyTime; entity.ModifyBy = model.ModifyBy; db.WC_MessageResponse.Add(entity); } db.SaveChanges(); } } catch (Exception ex) { throw; } }