Esempio n. 1
0
 public UserLogic(IRepository <User> repository)
 {
     if (repository == null)
     {
         this.userRepository          = new UserRepository(ContextFactory.GetNewContext());
         this.iRepository             = new IndicatorRepository(ContextFactory.GetNewContext());
         this.logRepository           = new LogRepository(ContextFactory.GetNewContext());
         this.userIndicatorRepository = new UserIndicatorRepository();
     }
     else
     {
         this.userRepository          = repository;
         this.userIndicatorRepository = new UserIndicatorRepository();
         this.iRepository             = new IndicatorRepository(ContextFactory.GetNewContext());
         this.logRepository           = new LogRepository(ContextFactory.GetNewContext());
     }
 }
Esempio n. 2
0
        public void DeleteIndicator(int id)
        {
            Indicator indicator = new Indicator();

            indicator.ID = id;
            if (!repository.Has(indicator))
            {
                throw new DoesNotExistsException("Indicador no existe");
            }
            UserIndicatorRepository userIndicatorRepository = new UserIndicatorRepository();

            indicator = repository.GetByID(id);
            List <UserIndicator> userIndicators = userIndicatorRepository.GetAll().ToList();

            foreach (UserIndicator userIndicator in userIndicators)
            {
                if (userIndicator.indicator == id)
                {
                    userIndicatorRepository.Delete(userIndicator);
                    userIndicatorRepository.Save();
                }
            }
            NodeRepository nr = new NodeRepository();

            if (!(repository.GetByID(id).Green == null))
            {
                nr.Delete(repository.GetByID(id).Green);
            }
            if (!(repository.GetByID(id).Red == null))
            {
                nr.Delete(repository.GetByID(id).Red);
            }
            if (!(repository.GetByID(id).Yellow == null))
            {
                nr.Delete(repository.GetByID(id).Yellow);
            }
            nr.Save();
            repository.Delete(indicator);
            repository.Save();
        }