示例#1
0
        public void AddIndicator(User user, Indicator indicator)
        {
            //   if ((GetIndicatorsByUser(user).Contains(indicator))) throw new AlreadyExistsException("Usuario ya tiene este indicador");
            if (IsAdmin(user))
            {
                throw new UserCantBeAdminException("Usuario no puede tener rol de administrador");
            }
            UserIndicator toAdd = new UserIndicator
            {
                user      = user.ID,
                indicator = indicator.ID,
            };

            userIndicatorRepository.Add(toAdd);
            userIndicatorRepository.Save();
        }
示例#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();
        }