public InsertLeadScoreRuleResponse CreateRule(InsertLeadScoreRuleRequest request) { Logger.Current.Verbose("Request for inserting LeadScore"); LeadScoreRuleViewModel ruleVM = request.LeadScoreRuleViewModel; LeadScoreRule leadScoreRule = Mapper.Map <LeadScoreRuleViewModel, LeadScoreRule>(ruleVM); isLeadScoreValid(leadScoreRule); bool isDuplicate = leadScoreRuleRepository.IsDuplicate(leadScoreRule); if (isDuplicate) { throw new UnsupportedOperationException("[|Rule already exists.|]"); } if ((leadScoreRule.ConditionID == LeadScoreConditionType.ContactNoteTagAdded || leadScoreRule.ConditionID == LeadScoreConditionType.ContactActionTagAdded) && leadScoreRule.Tags != null) { List <int> TagIDs = new List <int>(); var newTags = ruleVM.TagsList.Where(i => i.TagID == 0); var alreadycreatedtags = ruleVM.TagsList.Where(i => i.TagID != 0); TagIDs.AddRange(alreadycreatedtags.Select(x => x.TagID)); foreach (TagViewModel tag in newTags) { var insertedtag = tagService.SaveTag(new SaveTagRequest() { TagViewModel = tag }).TagViewModel; TagIDs.Add(insertedtag.TagID); } leadScoreRule.SelectedTagID = TagIDs.ToArray(); } int MaxLeadScoreID = leadScoreRuleRepository.GetMaxLeadScoreRuleID(); MaxLeadScoreID++; leadScoreRuleRepository.InsertLeadScoreRules(leadScoreRule, MaxLeadScoreID); if ((leadScoreRule.ConditionID == LeadScoreConditionType.ContactActionTagAdded || leadScoreRule.ConditionID == LeadScoreConditionType.ContactNoteTagAdded) && leadScoreRule.SelectedTagID != null && leadScoreRule.SelectedTagID.Any()) { IEnumerable <Tag> tags = tagRepository.FindByIDs(leadScoreRule.SelectedTagID); ReIndexLeadScoreTags(tags); } return(new InsertLeadScoreRuleResponse()); }
public ActionResult InsertLeadScore(LeadScoreRuleViewModel viewModel) { int UserID = this.Identity.ToUserID(); int AccountID = this.Identity.ToAccountID(); viewModel.CreatedBy = UserID; viewModel.ModifiedBy = UserID; viewModel.AccountID = AccountID; viewModel.CreatedOn = DateTime.Now.ToUniversalTime(); viewModel.ModifiedOn = DateTime.Now.ToUniversalTime(); InsertLeadScoreRuleRequest request = new InsertLeadScoreRuleRequest() { LeadScoreRuleViewModel = viewModel, RequestedBy = UserID, AccountId = AccountID }; leadScoreService.CreateRule(request); return(Json(new { success = true, response = "" }, JsonRequestBehavior.AllowGet)); }