public UserPetitionNotices_ItemViewModel(Coauthor coauthor) { if (coauthor != null) { CoauthorId = coauthor.Id; PetitionId = coauthor.Petition.Id; PetitionController = coauthor.Petition.Controller; PetitionTitle = coauthor.Petition.Title; } }
public _EditPetitionCoauthors_Coauthor(Coauthor coauthor) { Id = coauthor.Id; Name = coauthor.User.FullName; UserId = coauthor.UserId; if (!coauthor.IsAccepted.HasValue) Status = "нет ответа"; else if (coauthor.IsAccepted.Value) Status = "принято"; else Status = "отклонено"; }
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_CoauthorViewModel(Coauthor coauthor) { if (coauthor != null) { Name = coauthor.User.FullName; Avatar = ImageService.GetImageUrl<User>(coauthor.User.Avatar); UserId = coauthor.UserId; } }