Example #1
0
 public static Group UpdateGroup(EditGroupStruct newGroupData, bool saveChanges = true)
 {
     return Current.UpdateGroup(newGroupData, saveChanges);
 }
Example #2
0
        public Group UpdateGroup(EditGroupStruct newGroupData, bool saveChanges = true)
        {
            //var parentGroup = DataService.PerThread.GroupSet.Where(g => g.Id == groupData.ParentGroupId).SingleOrDefault();

            var parentGroup = DataService.PerThread.GroupSet.SingleOrDefault(g => g.Id == ConstHelper.RootGroupId); //TODO: пока нет вложенности, будет так
            if (parentGroup == null)
                throw new BusinessLogicException("В качестве родительской указана не существующая группа");

            if (ExistAnotherGroupWithLabel(newGroupData.Label, newGroupData.GroupId))
                throw new BusinessLogicException("Существует другая группа с указанным label (ЧПУ)");

            var group = DataService.PerThread.GroupSet.SingleOrDefault(g => g.Id == newGroupData.GroupId);
            if (group == null)
                throw new BusinessLogicException("Такой группы не существует");

            if (newGroupData.ElectionFrequency > 12)
                throw new BusinessLogicException("Выборы в группе не могут происходить реже чем раз в 12 месяцев");
            if (newGroupData.ElectionFrequency < 1)
                throw new BusinessLogicException("Выборы в группе не могут происходить реже чем раз в месяц");

            if (newGroupData.ModeratorsCount < 3)
                throw new BusinessLogicException("В группе должно быть не менее 3х модераторов");

            group.Name = newGroupData.Name;
            group.Label = newGroupData.Label;
            group.Summary = newGroupData.Summary;

            group.Categories.Clear();

            foreach (var cid in newGroupData.Categories)
            {
                var category = DataService.PerThread.GroupCategorySet.SingleOrDefault(x => x.Id == cid);
                if (category != null)
                    group.Categories.Add(category);
            }

            //IList<Tag> tagsToDelete = new List<Tag>();
            //IList<ExpertVote> evToDelete = new List<ExpertVote>();

            //foreach (var tag in group.Tags)
            //    if (!newTagsList.Contains(tag))
            //    {
            //        tagsToDelete.Add(tag);
            //        foreach (var gm in group.GroupMembers)
            //            if (gm.Expert != null)
            //                gm.Expert.Tags.Remove(tag);
            //        foreach (var ev in DataService.PerThread.ExpertVoteSet.Where(x => x.GroupMember.GroupId == group.Id && x.TagId == tag.Id))
            //            evToDelete.Add(ev);
            //    }
            //foreach (var ev in evToDelete)
            //    DataService.PerThread.ExpertVoteSet.DeleteObject(ev);
            //foreach (var tag in tagsToDelete)
            //    group.Tags.Remove(tag);

            //foreach (var tag in newTagsList)
            //    if (!group.Tags.Contains(tag))
            //        group.Tags.Add(tag);

            group.ModeratorsCount = newGroupData.ModeratorsCount;
            group.ElectionFrequency = newGroupData.ElectionFrequency;
            group.ParentGroup = parentGroup;
            group.PollQuorum = newGroupData.PollQuorum;
            group.ElectionQuorum = newGroupData.ElectionQuorum;

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

            CachService.DropViewModelByModel(group.Id);
            UserContextService.GroupMembersAbandon(group.Id);

            return group;
        }
Example #3
0
 public static Group UpdateGroup(EditGroupStruct newGroupData, bool saveChanges = true)
 {
     return(Current.UpdateGroup(newGroupData, saveChanges));
 }
Example #4
0
        public ActionResult Edit(GroupEditViewModel model)
        {
            if (!Request.IsAuthenticated)
                throw new AuthenticationException();

            var group = GroupService.GetGroupByLabelOrId(model.GroupId);

            var redirect = HideInvisibleGroup(group);
            if (redirect != null)
                return redirect;

            if (GroupService.UserInGroup(UserContext.Current.Id, model.GroupId).State != (byte)GroupMemberState.Moderator)
                throw new BusinessLogicException("Вы не являетесь модератором данной группы");

            if (group.Content.OfType<Election>().Count(x => !x.IsFinished) != 0)
                throw new BusinessLogicException("Редактирование группы закрыто на время выборов");

            if (ModelState.IsValid)
            {
                var groupData = new EditGroupStruct
                {
                    GroupId = model.GroupId,
                    ElectionFrequency = model.ElectionFrequency,
                    Label = model.Label,
                    ModeratorsCount = model.ModeratorsCount,
                    Name = model.Name,
                    ParentGroupId = model.ParentGroupId,
                    Summary = model.Summary,
                    PollQuorum = model.PollQuorum,
                    ElectionQuorum = model.ElectionQuorum,
                    Categories = new List<Guid>()

                };

                if (model.Category.HasValue) // TODO: можно переделать на много категорий
                    groupData.Categories.Add(model.Category.Value);

                GroupService.UpdateGroup(groupData);

                return RedirectToAction("details", new { id = group.Url });
            }

            return View(model);
        }
Example #5
0
        public Group UpdateGroup(EditGroupStruct newGroupData, bool saveChanges = true)
        {
            //var parentGroup = DataService.PerThread.GroupSet.Where(g => g.Id == groupData.ParentGroupId).SingleOrDefault();

            var parentGroup = DataService.PerThread.GroupSet.SingleOrDefault(g => g.Id == ConstHelper.RootGroupId); //TODO: пока нет вложенности, будет так

            if (parentGroup == null)
            {
                throw new BusinessLogicException("В качестве родительской указана не существующая группа");
            }

            if (ExistAnotherGroupWithLabel(newGroupData.Label, newGroupData.GroupId))
            {
                throw new BusinessLogicException("Существует другая группа с указанным label (ЧПУ)");
            }

            var group = DataService.PerThread.GroupSet.SingleOrDefault(g => g.Id == newGroupData.GroupId);

            if (group == null)
            {
                throw new BusinessLogicException("Такой группы не существует");
            }

            if (newGroupData.ElectionFrequency > 12)
            {
                throw new BusinessLogicException("Выборы в группе не могут происходить реже чем раз в 12 месяцев");
            }
            if (newGroupData.ElectionFrequency < 1)
            {
                throw new BusinessLogicException("Выборы в группе не могут происходить реже чем раз в месяц");
            }

            if (newGroupData.ModeratorsCount < 3)
            {
                throw new BusinessLogicException("В группе должно быть не менее 3х модераторов");
            }

            group.Name    = newGroupData.Name;
            group.Label   = newGroupData.Label;
            group.Summary = newGroupData.Summary;

            group.Categories.Clear();

            foreach (var cid in newGroupData.Categories)
            {
                var category = DataService.PerThread.GroupCategorySet.SingleOrDefault(x => x.Id == cid);
                if (category != null)
                {
                    group.Categories.Add(category);
                }
            }

            //IList<Tag> tagsToDelete = new List<Tag>();
            //IList<ExpertVote> evToDelete = new List<ExpertVote>();

            //foreach (var tag in group.Tags)
            //    if (!newTagsList.Contains(tag))
            //    {
            //        tagsToDelete.Add(tag);
            //        foreach (var gm in group.GroupMembers)
            //            if (gm.Expert != null)
            //                gm.Expert.Tags.Remove(tag);
            //        foreach (var ev in DataService.PerThread.ExpertVoteSet.Where(x => x.GroupMember.GroupId == group.Id && x.TagId == tag.Id))
            //            evToDelete.Add(ev);
            //    }
            //foreach (var ev in evToDelete)
            //    DataService.PerThread.ExpertVoteSet.DeleteObject(ev);
            //foreach (var tag in tagsToDelete)
            //    group.Tags.Remove(tag);

            //foreach (var tag in newTagsList)
            //    if (!group.Tags.Contains(tag))
            //        group.Tags.Add(tag);

            group.ModeratorsCount   = newGroupData.ModeratorsCount;
            group.ElectionFrequency = newGroupData.ElectionFrequency;
            group.ParentGroup       = parentGroup;
            group.PollQuorum        = newGroupData.PollQuorum;
            group.ElectionQuorum    = newGroupData.ElectionQuorum;

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

            CachService.DropViewModelByModel(group.Id);
            UserContextService.GroupMembersAbandon(group.Id);

            return(group);
        }