public bool CreateGroup(GroupCreateRAO model) { var newGroup = new GroupEntity { GroupName = model.GroupName, OwnerId = _userId, GroupInviteKey = GenerateRandomString(8) }; using (var ctx = new ApplicationDbContext()) { ctx.Groups.Add(newGroup); if (ctx.SaveChanges() != 1) { return(false); } var groups = ctx.Groups.Where(g => g.OwnerId == newGroup.OwnerId).ToList(); var id = groups[(groups.Count() - 1)].GroupId; var groupMember = new GroupMemberEntity { MemberId = _userId, GroupId = id, InGroup = true, IsMod = true }; ctx.GroupMembers.Add(groupMember); return(ctx.SaveChanges() == 1); } }
public bool JoinGroup(GroupJoinRAO rao) { using (var ctx = new ApplicationDbContext()) { var group = ctx.Groups.FirstOrDefault(g => g.GroupInviteKey == rao.GroupInviteKey); if (group == null) { return(false); } if (ctx.GroupMembers.Where(gm => gm.MemberId == _userId).Count() > 0) { return(false); } var groupMember = new GroupMemberEntity { MemberId = _userId, GroupId = group.GroupId, InGroup = false }; ctx.GroupMembers.Add(groupMember); return(ctx.SaveChanges() == 1); } }
public RequestResponse CreateGroup(GroupCreate model) { if (model == null) { return(BadResponse("Request Body was empty.")); } var groupEntity = new GroupEntity(model.GroupName, _userId, GetNewRandomKey(8)); _context.Groups.Add(groupEntity); if (_context.SaveChanges() != 1) { return(BadResponse("Could not create group")); } var memberEntity = new GroupMemberEntity(groupEntity.GroupId, _userId.ToString(), true, true); _context.GroupMembers.Add(memberEntity); if (_context.SaveChanges() != 1) { return(BadResponse("Could not create group member.")); } return(OkResponse("Group created successfully.")); }
public RequestResponse JoinGroup(string groupKey) { var groupEntity = _context.Groups.FirstOrDefault(g => g.GroupInviteCode == groupKey); if (groupEntity == null) { return(BadResponse("Invalid code.")); } if (CheckUserGroupAccess(groupEntity.GroupId)) { return(BadResponse("Already in group.")); } var memberEntity = new GroupMemberEntity(groupEntity.GroupId, _userId.ToString(), false, false); _context.GroupMembers.Add(memberEntity); if (_context.SaveChanges() != 1) { return(BadResponse("Could not join group.")); } return(OkResponse("Joined group successfully.")); }
public void AddMemberIntoGroup(GroupEntity groupEntity, AccountEntity accountEntity) { GroupMemberEntity groupMemberEntity = new GroupMemberEntity(); groupMemberEntity.AccountId = accountEntity.AccountId; groupMemberEntity.GroupId = groupEntity.GroupId; _context.GroupMembers.Add(groupMemberEntity); }
private RequestResponse PromoteOfficer(GroupMemberEntity member) { if (member == null) { return(BadResponse("Request Body was empty.")); } member.IsOfficer = true; if (_context.SaveChanges() != 1) { return(BadResponse("Unable to save changes.")); } return(OkResponse("Member promoted successfully.")); }
public async Task <GroupMemberEntity> GetMember(string chatId, long groupId, int number) { var info = await GetMemberEntiy(chatId, groupId, number); if (info == null) { info = new GroupMemberEntity { ChatId = chatId, GroupId = groupId, MemberNumber = number, }; _context.GroupMembers.Add(info); await _context.SaveChangesAsync(); } return(info); }
public JsonResult CreatePointOfInterest([FromBody] CommentDto comment) { string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name; try { //Check value enter from the form if (comment == null) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notInformationAccount)); return(Json(MessageResult.GetMessage(MessageType.NOT_INFORMATION_ACCOUNT))); } if (!ModelState.IsValid) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound)); return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND))); } GroupMemberEntity groupMemberEntity = _groupMemberRepository.GetGroupMemberByGroupIdAndAccountId(comment.groupId, comment.accountId); //Map data enter from the form to comment entity var comments = Mapper.Map <PPT.Database.Entities.CommentEntity>(comment); comments.GroupMemberId = groupMemberEntity.GroupMemberId; comments.DateTimeComment = DateTime.Now; comments.AccountId = comment.accountId; _commentRepository.CreateComment(comments); if (!_commentRepository.Save()) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.badRequest)); return(Json(MessageResult.GetMessage(MessageType.BAD_REQUEST))); } Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.commentSuccess)); return(Json(MessageResult.GetMessage(MessageType.COMMENTSUCCESS))); } catch (Exception ex) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message)); return(Json(MessageResult.ShowServerError(ex.Message))); } }
private RequestResponse DemoteOfficer(GroupMemberEntity member) { if (member == null) { return(BadResponse("Request Body was empty.")); } if (member.UserId == _userId.ToString()) { return(BadResponse("Cannot demote yourself.")); } member.IsOfficer = false; if (_context.SaveChanges() != 1) { return(BadResponse("Unable to save changes.")); } return(OkResponse("Member demoted successfully.")); }
public JsonResult AddMember([FromBody] AccountGroup account, int groupId) { string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name; try { if (account == null) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notEnterEmail)); return(Json(MessageResult.GetMessage(MessageType.NOT_ENTER_EMAIL))); } GroupMemberEntity groupMemberEntity = _groupMemberRepository.GetGroupMemberByGroupIdAndAccountId(groupId, account.accountID); if (groupMemberEntity != null) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.groupMemberExist)); return(Json(MessageResult.GetMessage(MessageType.GROUP_MEMBER_EXIST))); } if (!ModelState.IsValid) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound)); return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND))); } // get group by group Id in line 52 GroupEntity groupEntity = _groupRepository.GetGroupById(groupId); if (groupEntity == null) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.groupNotFound)); return(Json(MessageResult.GetMessage(MessageType.GROUP_NOT_FOUND))); } // get account by email. Email was input from the form AccountEntity accountEntity = _accountRepository.GetAccountById(account.accountID); if (accountEntity == null) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound)); return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND))); } //This is query add member into this group _groupRepository.AddMemberIntoGroup(groupEntity, accountEntity); List <ExamEntity> listExamEntity = _examRepository.GetListExamByGroupId(groupId); foreach (var item in listExamEntity) { AccountExamEntity accountExamEntity = new AccountExamEntity(); accountExamEntity.AccountId = accountEntity.AccountId; accountExamEntity.ExamId = item.ExamId; accountExamEntity.IsStatus = "Do Exam"; _accountExamRepository.CreateAccountExam(accountExamEntity); } if (!_groupRepository.Save()) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.badRequest)); return(Json(MessageResult.GetMessage(MessageType.BAD_REQUEST))); } Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.memberAdded)); return(Json(MessageResult.GetMessage(MessageType.MEMBER_ADDED))); } catch (Exception ex) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message)); return(Json(MessageResult.ShowServerError(ex.Message))); } }
public void DeleteMember(GroupMemberEntity member) { _context.GroupMembers.Remove(member); }
/// <summary> /// 分析消息结构 /// </summary> /// <param name="MsgList"></param> private static void AnalyseMsg(List <AddMsgListItemEntity> MsgList) { try { //遍历所有消息项 for (int index = 0; index < MsgList.Count; index++) { AddMsgListItemEntity ali = MsgList[index]; //消息体 MsgEntity me = new MsgEntity(); //二次封装 me.IsCanAutoReply = true; // WebwxStatusNotify(ali.FromUserName, ali.ToUserName); if (ali.FromUserName == CommonDefine.BaseContact.User.UserName) { return; } //取得消息来源联系人信息 var CustomName = from item in CommonDefine.ContactsList.MemberList where item.UserName == ali.FromUserName select item; if (CustomName == null || CustomName.ToList().Count <= 0) { //当前联系人列表中找不到此用户 try { //此处进行联系人刷新 RefreshContacts(); CustomName = from item in CommonDefine.ContactsList.MemberList where item.UserName == ali.FromUserName select item; if (CustomName == null || CustomName.ToList().Count <= 0)//未找到消息来源 { return; } } catch (Exception ex) { LogWriter.Write("刷新联系人发生异常,异常信息是:" + ex.Message, LogPathDefine.ExceptionLogPath); } } MemberListItemEntity Mlie = CustomName.ToList().SingleOrDefault(); try { if (Mlie.UserName.Contains("@@")) { //群消息处理 GroupMemberEntity Gme = SelectGroupMumber(ali); if (Gme == null) { //刷新群成员 GetGroupContactsMethod(CommonDefine.ContactsList.MemberList); Gme = SelectGroupMumber(ali); } if (ali.Content.Contains(":")) { string[] a = ali.Content.Split(':'); ali.Content = Gme.NickName + ":" + a[1].Replace("<br/>", ""); } me.GroupMember = Gme; } } catch (Exception ex) { LogWriter.Write("替换群成员名称失败,异常信息为:" + ex.Message, LogPathDefine.ExceptionLogPath); } //消息列表实体 me.MsgOwer = Mlie; me.MsgContent = ali.Content; me.MsgOwerType = MsgOwerTypeEnum.AccepterMsg; me.IsCanAutoReply = Mlie.IsCanAutoReply; #region 储存消息 if (ali.MsgType == (int)MsgTypeEnum.Voice) { me.MsgType = MsgTypeEnum.Voice; //语音消息 string Url = string.Format(UrlDefine.VoiceUrl, ali.MsgId, CommonDefine.LoginResult.skey); string FileId = MethodsHelper.MsgSaveFile(DirectoryDefine.VoiceMsgPath);//获取FileId //根据FileID创建本地的语音对象 List <byte> list = HttpMethods.GetFile(Url, Environment.CurrentDirectory + "\\" + DirectoryDefine.VoiceMsgPath + "\\" + FileId + ".mp3", CommonDefine.Cookies).ContentData as List <byte>; me.MsgTime = DateTime.Now; me.FileId = FileId; me.FilePath = Environment.CurrentDirectory + "\\" + DirectoryDefine.VoiceMsgPath + "\\" + me.FileId + ".mp3"; } else if (ali.MsgType == (int)MsgTypeEnum.Picture) { me.MsgType = MsgTypeEnum.Picture; //图片消息 string Url = string.Format(UrlDefine.ImgUrlBig, ali.MsgId, CommonDefine.LoginResult.skey); string FileId = MethodsHelper.MsgSaveFile(DirectoryDefine.ImageMsgPath);//获取FileId //根据FileID创建本地的语音对象 List <byte> list = HttpMethods.GetFile(Url, Environment.CurrentDirectory + "\\" + DirectoryDefine.ImageMsgPath + "\\" + FileId + ".jpg", CommonDefine.Cookies).ContentData as List <byte>; //获取缩略图 HttpMethods.GetFile(string.Format(UrlDefine.ImgUrl, ali.MsgId, CommonDefine.LoginResult.skey), Environment.CurrentDirectory + "\\" + DirectoryDefine.ImageMsgTempPath + "\\" + FileId + ".jpg", CommonDefine.Cookies); //将下载下来的MP3文件转成Base64进行储存 //string Base64Str = Convert.ToBase64String(list.ToArray()); me.MsgTime = DateTime.Now; me.FileId = FileId; me.FilePath = Environment.CurrentDirectory + "\\" + DirectoryDefine.ImageMsgPath + "\\" + FileId + ".jpg";// me.FileTempPath = Environment.CurrentDirectory + "\\" + DirectoryDefine.ImageMsgTempPath + "\\" + FileId + ".jpg"; } else if (ali.MsgType == (int)MsgTypeEnum.Gif) { //TODO:GIF消息 me.MsgType = MsgTypeEnum.Gif; //语音消息 string Url = string.Format(UrlDefine.ImgUrlBig, ali.MsgId, CommonDefine.LoginResult.skey); string FileId = MethodsHelper.MsgSaveFile(DirectoryDefine.ImageMsgGifPath);//获取FileId HttpMethods.GetFile(Url, Environment.CurrentDirectory + "\\" + DirectoryDefine.ImageMsgGifPath + "\\" + FileId + ".gif", CommonDefine.Cookies); HttpMethods.GetFile(string.Format(UrlDefine.ImgUrl, ali.MsgId, CommonDefine.LoginResult.skey), Environment.CurrentDirectory + "\\" + DirectoryDefine.ImageMsgTempPath + "\\" + FileId + ".jpg", CommonDefine.Cookies); me.MsgTime = DateTime.Now; me.FileId = FileId; me.FilePath = Environment.CurrentDirectory + "\\" + DirectoryDefine.ImageMsgGifPath + "\\" + FileId + ".gif";// me.FileTempPath = Environment.CurrentDirectory + "\\" + DirectoryDefine.ImageMsgTempPath + "\\" + FileId + ".jpg"; } else if (ali.MsgType == (int)MsgTypeEnum.Video) { me.MsgType = MsgTypeEnum.Video; //视频消息 string Url = string.Format(UrlDefine.VideoUrl, ali.MsgId, HttpUtility.UrlEncode(CommonDefine.LoginResult.skey)); string FileId = MethodsHelper.MsgSaveFile(DirectoryDefine.VideoMsgPath);//获取FileId HttpMethods.GetFile(string.Format(UrlDefine.ImgUrl, ali.MsgId, CommonDefine.LoginResult.skey), Environment.CurrentDirectory + "\\" + DirectoryDefine.ImageMsgTempPath + "\\" + FileId + ".jpg", CommonDefine.Cookies); //根据FileID创建本地的语音对象 List <byte> list = HttpMethods.GetVideo(Url, Environment.CurrentDirectory + "\\" + DirectoryDefine.VideoMsgPath + "\\" + FileId + ".mp4", CommonDefine.Cookies); me.MsgTime = DateTime.Now; me.FileId = FileId; me.FilePath = Environment.CurrentDirectory + "\\" + DirectoryDefine.VideoMsgPath + "\\" + FileId + ".mp4";// me.FileTempPath = Environment.CurrentDirectory + "\\" + DirectoryDefine.ImageMsgTempPath + "\\" + FileId + ".jpg"; } else if (ali.MsgType == 1 && !string.IsNullOrWhiteSpace(ali.Url)) { //地图消息 me.MsgType = MsgTypeEnum.Map; me.MsgUrl = ali.Url; //地图消息 string Url = string.Format(UrlDefine.MapUrl, ali.MsgId); //HttpHelper.ContentType = ""; string FileId = MethodsHelper.MsgSaveFile(DirectoryDefine.MapImageMsgPath);//获取FileId //根据FileID创建本地的语音对象 HttpMethods.GetFile(Url, Environment.CurrentDirectory + "\\" + DirectoryDefine.MapImageMsgPath + "\\" + FileId + ".jpg", CommonDefine.Cookies); me.FilePath = Environment.CurrentDirectory + "\\" + DirectoryDefine.MapImageMsgPath + "\\" + FileId + ".jpg"; me.MsgTime = DateTime.Now; } else if (ali.MsgType == (int)MsgTypeEnum.SystemMsg) { me.MsgType = MsgTypeEnum.SystemMsg; me.MsgTime = DateTime.Now; } else { me.MsgType = MsgTypeEnum.Text; me.MsgTime = DateTime.Now; } LogWriter.Write(me.MsgContent.ToString(), LogPathDefine.WeChatLogPath); CommonMethodCallBackHandlers.OnReceivedMsgAnalyseMsgCompleted(me); SetAutoRepate(CommonDefine.WhiteUserList, LoadAutoReplyConfig(ConfigDefine.WeChatAutoReplyPath), me.MsgOwer.UserName, me); #endregion } } catch (Exception ex) { LogWriter.Write(ex.Message, LogPathDefine.ExceptionLogPath); } }