public Message Send(MessageStruct messageInfo) { if (DataService.PerThread.BaseUserSet.Count(u => u.Id == messageInfo.RecipientId) == 0) throw new BusinessLogicException("Получатель не найден!"); if (messageInfo.AuthorId.HasValue) { if (DataService.PerThread.BaseUserSet.SingleOrDefault(u => u.Id == messageInfo.AuthorId) == null) throw new BusinessLogicException("Отправитель не найден!"); if (messageInfo.AuthorId == messageInfo.RecipientId) throw new BusinessLogicException("Нельзя посылать самому себе!"); } var message = new Message { AuthorId = messageInfo.AuthorId, Date = messageInfo.Date, RecipientId = messageInfo.RecipientId, Text = messageInfo.Text, Type = messageInfo.Type, IsDeletedByAuthor = false, IsDeletedByRecipient = false }; DataService.PerThread.MessageSet.AddObject(message); DataService.PerThread.SaveChanges(); UserContextService.Abandon(message.RecipientId); return message; }
public static void SendToGroup(Group group, string text, MessageType type, GroupMessageRecipientType recipientType = GroupMessageRecipientType.Members, Guid? authorId = null, DateTime? date = null) { if (!date.HasValue) date = DateTime.Now; var messageInfo = new MessageStruct { AuthorId = authorId, Text = text, Type = (byte)type, Date = date.Value }; Current.SendToGroup(group, messageInfo, recipientType); }
public void SendToGroup(Group group, MessageStruct messageInfo, GroupMessageRecipientType recipientType) { var recipientIdList = new List <Guid>(); if (recipientType.HasFlag(GroupMessageRecipientType.Members)) { recipientIdList.AddRange(DataService.PerThread.GroupMemberSet.Where( x => x.GroupId == group.Id && x.State == (byte)GroupMemberState.Approved).Select(uig => uig.UserId) .ToList()); } if (recipientType.HasFlag(GroupMessageRecipientType.Moderators)) { recipientIdList.AddRange(DataService.PerThread.GroupMemberSet.Where( x => x.GroupId == group.Id && x.State == (byte)GroupMemberState.Moderator).Select(uig => uig.UserId) .ToList()); } if (recipientType.HasFlag(GroupMessageRecipientType.NotApprovedUsers)) { recipientIdList.AddRange(DataService.PerThread.GroupMemberSet.Where( x => x.GroupId == group.Id && x.State == (byte)GroupMemberState.NotApproved).Select(uig => uig.UserId) .ToList()); } recipientIdList = recipientIdList.Distinct().ToList(); if (recipientIdList.Count > 0) { foreach (var userId in recipientIdList) { var message = new MessageStruct { AuthorId = messageInfo.AuthorId, RecipientId = userId, Text = messageInfo.Text, Type = messageInfo.Type, Date = messageInfo.Date }; Send(message); } DataService.PerThread.SaveChanges(); } UserContextService.GroupMembersAbandon(group.Id); }
public static Message Send(Guid? authorId, Guid recipientId, string text, MessageType type, DateTime? date = null) { if (!date.HasValue) date = DateTime.Now; var messageInfo = new MessageStruct { AuthorId = authorId, RecipientId = recipientId, Text = text, Type = (byte)type, Date = date.Value }; return Current.Send(messageInfo); }
public static void SendToGroup(Group group, string text, MessageType type, GroupMessageRecipientType recipientType = GroupMessageRecipientType.Members, Guid?authorId = null, DateTime?date = null) { if (!date.HasValue) { date = DateTime.Now; } var messageInfo = new MessageStruct { AuthorId = authorId, Text = text, Type = (byte)type, Date = date.Value }; Current.SendToGroup(group, messageInfo, recipientType); }
public static Message Send(Guid?authorId, Guid recipientId, string text, MessageType type, DateTime?date = null) { if (!date.HasValue) { date = DateTime.Now; } var messageInfo = new MessageStruct { AuthorId = authorId, RecipientId = recipientId, Text = text, Type = (byte)type, Date = date.Value }; return(Current.Send(messageInfo)); }
public Message Send(MessageStruct messageInfo) { if (DataService.PerThread.BaseUserSet.Count(u => u.Id == messageInfo.RecipientId) == 0) { throw new BusinessLogicException("Получатель не найден!"); } if (messageInfo.AuthorId.HasValue) { if (DataService.PerThread.BaseUserSet.SingleOrDefault(u => u.Id == messageInfo.AuthorId) == null) { throw new BusinessLogicException("Отправитель не найден!"); } if (messageInfo.AuthorId == messageInfo.RecipientId) { throw new BusinessLogicException("Нельзя посылать самому себе!"); } } var message = new Message { AuthorId = messageInfo.AuthorId, Date = messageInfo.Date, RecipientId = messageInfo.RecipientId, Text = messageInfo.Text, Type = messageInfo.Type, IsDeletedByAuthor = false, IsDeletedByRecipient = false }; DataService.PerThread.MessageSet.AddObject(message); DataService.PerThread.SaveChanges(); UserContextService.Abandon(message.RecipientId); return(message); }
public static void SendToGroup(Group group, MessageStruct messageInfo, GroupMessageRecipientType recipientType = GroupMessageRecipientType.Members) { Current.SendToGroup(group, messageInfo, recipientType); }
public static void Send(MessageStruct messageInfo) { Current.Send(messageInfo); }
public Coauthor InvitePetitionCoauthor(PetitionCoauthorContainer data, Guid userId, bool saveChanges) { if (string.IsNullOrWhiteSpace(data.UserName)) throw new BusinessLogicException("Не указано ФИО пользователя"); var petition = DataService.PerThread.ContentSet.OfType<Petition>().SingleOrDefault(p => p.Id == data.PetitionId); if (petition == null) throw new BusinessLogicException("Не найдена петиция с данным идентификатором"); if (petition.State != (byte)ContentState.Draft) throw new BusinessLogicException("Приглашать соавторов можно только в еще неопубликованные петиции"); if (petition.AuthorId != userId) throw new BusinessLogicException("Вы не являетесь автором данной петиции"); var username = data.UserName.Trim().Split(' '); if (username.Count() != 3) throw new BusinessLogicException("Введены неверные данные"); var surname = username[0]; var firstname = username[1]; var patronymic = username[2]; var user = DataService.PerThread.BaseUserSet .OfType<User>().SingleOrDefault(u => u.SurName == surname && u.FirstName == firstname && u.Patronymic == patronymic); if (user == null) throw new BusinessLogicException("Пользователь не найден"); if (user.Id == userId) throw new BusinessLogicException("Вы уже являетесь автором петиции"); if (petition.GroupId.HasValue && petition.IsPrivate) { var uig = GroupService.UserInGroup(user.Id, petition.GroupId.Value); if (uig == null) throw new BusinessLogicException("Данная петиция только для членов группы, а указанный пользователь в группе не состоит"); if (uig.State == (byte)GroupMemberState.NotApproved) throw new BusinessLogicException("Данная петиция только для членов группы, а указанный пользователь еще не одобрен модераторами"); } if (DataService.PerThread.CoauthorSet.Count(c => c.UserId == user.Id & c.PetitionId == data.PetitionId) > 0) throw new BusinessLogicException("Уже отправлено приглашение данному пользователю"); var coauthor = new Coauthor { PetitionId = data.PetitionId, UserId = user.Id }; DataService.PerThread.CoauthorSet.AddObject(coauthor); if (saveChanges) DataService.PerThread.SaveChanges(); var date = DateTime.Now; var msg = new MessageStruct { AuthorId = petition.AuthorId, RecipientId = coauthor.UserId, Text = MessageComposer.ComposePetitionNotice(coauthor.PetitionId, "Вы приглашены на соавторство в петиции" + " <a href='" + UrlHelper.GetUrl("petitionnotices", "user", false) + "'>Ответить</a>."), Type = (byte)MessageType.PetitionNotice, Date = date }; MessageService.Send(msg); return coauthor; }
public Petition DeletePetitionCoauthor(Guid id, Guid userId, bool saveChanges) { var coauthor = DataService.PerThread.CoauthorSet.SingleOrDefault(x => x.Id == id); if (coauthor == null) throw new BusinessLogicException("Неверный идентификатор соавтора"); var petition = coauthor.Petition; if (coauthor.Petition.State != (byte)ContentState.Draft) throw new BusinessLogicException("Удалять соавторов можно только из еще неопубликованных петиций"); if (coauthor.Petition.AuthorId != userId) throw new BusinessLogicException("Вы не являетесь автором данной петиции"); var msg = new MessageStruct(); if (petition.AuthorId.HasValue) msg.AuthorId = petition.AuthorId.Value; if (!coauthor.IsAccepted.HasValue) { var date = DateTime.Now; msg.Date = date; msg.RecipientId = coauthor.UserId; msg.Text = MessageComposer.ComposePetitionNotice(coauthor.PetitionId, "Автор петиции удалил приглашение на соавторство."); msg.Type = (byte)MessageType.PetitionNotice; MessageService.Send(msg); } else if (coauthor.IsAccepted.Value) { var date = DateTime.Now; msg.Date = date; msg.RecipientId = coauthor.UserId; msg.Text = MessageComposer.ComposePetitionNotice(coauthor.PetitionId, "Автор петиции удалил вас из соавторов"); msg.Type = (byte)MessageType.PetitionNotice; MessageService.Send(msg); } DataService.PerThread.CoauthorSet.DeleteObject(coauthor); if (saveChanges) DataService.PerThread.SaveChanges(); return petition; }
public void SendToGroup(Group group, MessageStruct messageInfo, GroupMessageRecipientType recipientType) { var recipientIdList = new List<Guid>(); if (recipientType.HasFlag(GroupMessageRecipientType.Members)) recipientIdList.AddRange(DataService.PerThread.GroupMemberSet.Where( x => x.GroupId == group.Id && x.State == (byte)GroupMemberState.Approved).Select(uig => uig.UserId) .ToList()); if (recipientType.HasFlag(GroupMessageRecipientType.Moderators)) recipientIdList.AddRange(DataService.PerThread.GroupMemberSet.Where( x => x.GroupId == group.Id && x.State == (byte)GroupMemberState.Moderator).Select(uig => uig.UserId) .ToList()); if (recipientType.HasFlag(GroupMessageRecipientType.NotApprovedUsers)) recipientIdList.AddRange(DataService.PerThread.GroupMemberSet.Where( x => x.GroupId == group.Id && x.State == (byte)GroupMemberState.NotApproved).Select(uig => uig.UserId) .ToList()); recipientIdList = recipientIdList.Distinct().ToList(); if (recipientIdList.Count > 0) { foreach (var userId in recipientIdList) { var message = new MessageStruct { AuthorId = messageInfo.AuthorId, RecipientId = userId, Text = messageInfo.Text, Type = messageInfo.Type, Date = messageInfo.Date }; Send(message); } DataService.PerThread.SaveChanges(); } UserContextService.GroupMembersAbandon(group.Id); }