public ActionResult EditPetition(_EditPetitionViewModel model)
        {
            if (!Request.IsAuthenticated)
                throw new AuthenticationException();

            if (ModelState.IsValid)
            {
                PetitionContainer data = new PetitionContainer
                {
                    GroupId = model.GroupId,
                    Id = model.Id,
                    IsPrivate = model.IsPrivate,
                    Tags = model.TagTitles,
                    Text = model.Text,
                    Title = model.Title
                };

                Petition petition = VotingService.EditPetition(data, UserContext.Current.Id);

                return RedirectToAction("petition", petition.Controller, new { id = petition.Id });
            }

            if (model.GroupId != null)
                View("../group/editpetition", model);

            return View("../user/editpetition", model);
        }
Exemple #2
0
 public static Petition EditPetition(PetitionContainer data, Guid userId, bool saveChanges = true)
 {
     return _votingService.EditPetition(data, userId, saveChanges);
 }
        public Petition CreatePetition(PetitionContainer data, Guid userId, bool saveChanges)
        {
            if (data.GroupId.HasValue)
            {
                var uig = GroupService.UserInGroup(userId, data.GroupId.Value);
                if (uig == null)
                    throw new BusinessLogicException("Только члены могут создавать петиции в группе");

                if (uig.State == (byte)GroupMemberState.NotApproved)
                    throw new BusinessLogicException("Вы ожидаете одобрения модератора");
            }

            var petition = new Petition
            {
                AuthorId = userId,
                CreationDate = DateTime.Now,
                Duration = 365,
                GroupId = data.GroupId.HasValue ? data.GroupId.Value : (Guid?)null,
                IsDiscussionClosed = false,
                IsPrivate = data.IsPrivate,
                Signers = new List<User>(),
                State = (byte)ContentState.Draft,
                Tags = TagsHelper.ConvertStringToTagList(data.Tags, data.GroupId),
                Text = data.Text,
                Title = data.Title
            };

            var user = DataService.PerThread.BaseUserSet.OfType<User>().SingleOrDefault(u => u.Id == userId);
            if (user == null)
                throw new BusinessLogicException("Перезайдите");

            petition.Signers.Add(user);

            DataService.PerThread.ContentSet.AddObject(petition);

            if (saveChanges)
                DataService.PerThread.SaveChanges();

            return petition;
        }
        public Petition EditPetition(PetitionContainer data, Guid userId, bool saveChanges)
        {
            var petition = DataService.PerThread.ContentSet.OfType<Petition>().SingleOrDefault(p => p.Id == data.Id);
            if (petition == null)
                throw new BusinessLogicException("Не найдена петиция с указанным идентификатором");

            if (petition.State != (byte)ContentState.Draft)
                throw new BusinessLogicException("Редактировать можно только черновые петиции");

            if (petition.GroupId.HasValue)
            {
                var uig = GroupService.UserInGroup(userId, petition.GroupId.Value);

                if (petition.AuthorId.HasValue)
                {
                    if (!(uig.State == (byte)GroupMemberState.Moderator || petition.AuthorId.Value == userId))
                        throw new BusinessLogicException("У вас нет прав редактировать данную петицию");
                }
                else if (uig.State != (byte)GroupMemberState.Moderator)
                    throw new BusinessLogicException("У вас нет прав редактировать данную петицию");
            }
            else if (petition.AuthorId != userId)
                throw new BusinessLogicException("Вы не являетесть автором данной петиции");

            petition.Title = data.Title;
            petition.Text = data.Text;
            petition.IsPrivate = data.IsPrivate;
            petition.Tags.Clear();

            foreach (var tag in TagsHelper.ConvertStringToTagList(data.Tags, petition.GroupId))
                petition.Tags.Add(tag);

            var user = DataService.PerThread.BaseUserSet.OfType<User>().SingleOrDefault(u => u.Id == userId);
            if (user == null)
                throw new BusinessLogicException("Перезайдите");

            if (saveChanges)
                DataService.PerThread.SaveChanges();

            return petition;
        }
Exemple #5
0
 public static Petition CreatePetition(PetitionContainer data, Guid userId, bool saveChanges = true)
 {
     return(_votingService.CreatePetition(data, userId, saveChanges));
 }