예제 #1
0
        public ActionResult AddInterestRelationship(CreateInterestRelationshipViewModel createInterestRelationshipViewModel)
        {
            Interest mainInterest = _interestTasks.Get(createInterestRelationshipViewModel.Id);

            if (ModelState.IsValid)
            {
                var relatedInterestListDto = new RelatedInterestListDto
                {
                    OriginalInterest = new RelatedInterestListDto.RelatedInterestDto(mainInterest.Id, null, mainInterest.Name, mainInterest.Slug),
                    WeightedRelatedInterestDtos = createInterestRelationshipViewModel
                        .UserInterests
                        .Select(x => new RelatedInterestListDto.WeightedRelatedInterestDto
                        {
                            Weight = createInterestRelationshipViewModel.RelationShipType,
                            Interest = new RelatedInterestListDto.RelatedInterestDto(x.Id, x.CategoryId, x.Name, null)
                        }).ToList()
                };

                _interestTasks.CreateRelationships(relatedInterestListDto);
                this.FlashSuccess("Updated Relationships");
                return RedirectToAction("SpecificInterest", new {Id = mainInterest.Slug});
            }

            RouteData.Values["action"] = "SpecificInterest";
            return SpecificInterest(mainInterest.Slug);
        }
예제 #2
0
        public void CreateRelationships(RelatedInterestListDto relatedInterestListDto)
        {
            foreach (var newInterest in relatedInterestListDto.WeightedRelatedInterestDtos.Select(x => x.Interest).Where(x => x.Id == 0))
            {
                var createdInterest = Create(newInterest.Name, newInterest.ParentId);
                newInterest.Id = createdInterest.Id;
            }

            if (relatedInterestListDto.WeightedRelatedInterestDtos.Any(x => x.Interest.Id == relatedInterestListDto.OriginalInterest.Id))
            {
                throw new RulesException("Interest", "An interest cannot have a relationship with itself");
            }

            _interestRepository.CreateRelationships(relatedInterestListDto);
        }