Пример #1
0
        public ActionResult InvitePetitionCoauthor(_EditPetitionCoauthorsViewModel model)
        {
            if (!Request.IsAuthenticated)
                throw new AuthenticationException();

            PetitionCoauthorContainer data = new PetitionCoauthorContainer
            {
                PetitionId = model.PetitionId,
                UserName = model.UserNameForInvite
            };

            VotingService.InvitePetitionCoauthor(data, UserContext.Current.Id);

            return Redirect(Request.UrlReferrer.PathAndQuery);
        }
Пример #2
0
        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;
        }
Пример #3
0
 public static Coauthor InvitePetitionCoauthor(PetitionCoauthorContainer data, Guid userId, bool saveChanges = true)
 {
     return _votingService.InvitePetitionCoauthor(data, userId, saveChanges);
 }
Пример #4
0
 public static Coauthor InvitePetitionCoauthor(PetitionCoauthorContainer data, Guid userId, bool saveChanges = true)
 {
     return(_votingService.InvitePetitionCoauthor(data, userId, saveChanges));
 }