Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
0
        public IActionResult EditDuplicateRule(Guid id)
        {
            EditDuplicateRuleModel model = new EditDuplicateRuleModel();

            if (!id.Equals(Guid.Empty))
            {
                var entity = _duplicateRuleFinder.FindById(id);
                if (entity != null)
                {
                    entity.CopyTo(model);
                    model.Conditions = _duplicateRuleConditionService.Query(n => n.Where(w => w.DuplicateRuleId == entity.DuplicateRuleId));
                    return(View(model));
                }
            }
            return(NotFound());
        }
Ejemplo n.º 3
0
        public IActionResult Post(EditDuplicateRuleModel model)
        {
            if (ModelState.IsValid)
            {
                var entity = _duplicateRuleFinder.FindById(model.DuplicateRuleId.Value);
                entity.Description = model.Description;
                entity.Name        = model.Name;
                entity.Intercepted = model.Intercepted;
                _duplicateRuleUpdater.Update(entity);
                var conditions = _duplicateRuleConditionService.Query(n => n.Where(w => w.DuplicateRuleId == entity.DuplicateRuleId));
                int i          = 0;
                foreach (var item in model.AttributeId)
                {
                    var id        = model.DetailId[i];
                    var condition = new DuplicateRuleCondition();
                    condition.DuplicateRuleId  = entity.DuplicateRuleId;
                    condition.EntityId         = model.EntityId;
                    condition.IgnoreNullValues = model.IgnoreNullValues[i];
                    condition.IsCaseSensitive  = model.IsCaseSensitive[i];
                    condition.AttributeId      = item;
                    if (id.Equals(Guid.Empty))
                    {
                        condition.DuplicateRuleConditionId = Guid.NewGuid();
                        _duplicateRuleConditionService.Create(condition);
                    }
                    else
                    {
                        condition.DuplicateRuleConditionId = id;
                        _duplicateRuleConditionService.Update(condition);
                        conditions.Remove(conditions.Find(n => n.DuplicateRuleConditionId == id));
                    }

                    i++;
                }
                //delete lost detail
                var lostid = conditions.Select(n => n.DuplicateRuleConditionId).ToList();
                _duplicateRuleConditionService.DeleteById(lostid);

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

            return(UpdateFailure(msg));
        }