Ejemplo n.º 1
0
        public IActionResult CreateDuplicateRule(EditDuplicateRuleModel model)
        {
            if (ModelState.IsValid)
            {
                var entity = new DuplicateRule();
                model.CopyTo(entity);
                entity.DuplicateRuleId = Guid.NewGuid();
                entity.CreatedBy       = CurrentUser.SystemUserId;
                var conditions = new List <DuplicateRuleCondition>();
                int i          = 0;
                foreach (var item in model.AttributeId)
                {
                    var cd = new DuplicateRuleCondition
                    {
                        DuplicateRuleConditionId = Guid.NewGuid(),
                        DuplicateRuleId          = entity.DuplicateRuleId,
                        EntityId         = model.EntityId,
                        IgnoreNullValues = model.IgnoreNullValues[i],
                        IsCaseSensitive  = model.IsCaseSensitive[i],
                        AttributeId      = item
                    };
                    conditions.Add(cd);
                    i++;
                }
                entity.Conditions = conditions;

                _duplicateRuleCreater.Create(entity);
                return(CreateSuccess(new { id = entity.DuplicateRuleId }));
            }
            var msg = GetModelErrors(ModelState);

            return(CreateFailure(msg));
        }
Ejemplo n.º 2
0
 public bool Import(Guid solutionId, IList <DuplicateRule> duplicateRules)
 {
     if (duplicateRules.NotEmpty())
     {
         foreach (var item in duplicateRules)
         {
             var entity = _duplicateRuleFinder.FindById(item.DuplicateRuleId);
             if (entity != null)
             {
                 _duplicateRuleUpdater.Update(item);
                 if (item.Conditions.NotEmpty())
                 {
                     _duplicateRuleConditionService.DeleteByParentId(entity.DuplicateRuleId);
                     foreach (var cnd in item.Conditions)
                     {
                         cnd.DuplicateRuleId = item.DuplicateRuleId;
                     }
                     _duplicateRuleConditionService.CreateMany(item.Conditions);
                 }
             }
             else
             {
                 item.CreatedBy      = _appContext.GetFeature <ICurrentUser>().SystemUserId;
                 item.SolutionId     = solutionId;
                 item.ComponentState = 0;
                 item.CreatedOn      = DateTime.Now;
                 _duplicateRuleCreater.Create(item);
             }
         }
     }
     return(true);
 }