public IEnumerable <SubItemEntity> GetByItemId(int itemId)
        {
            var SubItems = _subItemService.GetByItemId(itemId);

            var validSubItems = SubItems.ToList()
                                .Where(x => x.IsActive == true);

            return(validSubItems);
        }
Ejemplo n.º 2
0
        private void ValidateRelation(int companyId, int itemId, int?subItemId)
        {
            var company = _companyService.GetById(companyId);

            if (company == null)
            {
                throw new InvalidCompanyException();
            }

            var companyItems = _itemService.GetByCompanyId(companyId);
            var foundItem    = companyItems.FirstOrDefault(x => x.Id == itemId);

            if (foundItem == null)
            {
                throw new InvalidItemException();
            }

            if (subItemId != null)
            {
                if (!foundItem.Desdobramento)
                {
                    throw new AtomicItemException();
                }

                var itemSubitems = _subItemService.GetByItemId(itemId);
                var foundSubItem = itemSubitems.Where(x => x.Id == subItemId);
                if (foundSubItem == null)
                {
                    throw new InvalidSubItemException();
                }
            }
        }
Ejemplo n.º 3
0
        public CompanyEntity GetAllEntitiesRelations(int companyId)
        {
            var company = _companyService.GetById(companyId);

            if (company == null)
            {
                return(null);
            }

            // obtem todas relações dos items >> subitens
            var collection = _itemService.GetAll();

            if (collection.Count() == 0)
            {
                return(null);
            }

            company.Items = collection.ToList();

            // pra cada item da relação
            foreach (var item in company.Items)
            {
                // verifica se a empresa tem este item >> flaga
                var itemFromCompany = _itemService.GetByCompanyId(companyId).Where(x => x.Id == item.Id).FirstOrDefault();
                item.IsRelated = itemFromCompany != null ? true : false;


                // verifica os subitens deste item dado a empresa >> flaga
                item.SubItems = _subItemService.GetByItemId(item.Id).ToList();
                foreach (var subitem in item.SubItems)
                {
                    var subitemFromCompany = _subItemService.GetSubItemRelatedToCompanyAndItem(companyId, item.Id, subitem.Id);
                    subitem.IsRelated = subitemFromCompany != null ? true : false;
                }
            }
            return(company);
        }