Exemple #1
0
        public async Task <List <ContractPartViewModel> > FindShortestPath(ContractInputModel model)
        {
            if (model == null)
            {
                throw new ValidationBusinessException(ValidationMessage.InputInvalid);
            }

            if (model.FromId == Guid.Empty || model.ToId == Guid.Empty)
            {
                throw new ValidationBusinessException(ValidationMessage.IdInvalid);
            }

            if (model.FromId == model.ToId)
            {
                throw new ValidationBusinessException(ValidationMessage.ContractInvalid);
            }

            var result = Enumerable.Empty <ContractPartViewModel>().ToList();

            var nodes = await GetNodes();

            if (nodes.Count == 0)
            {
                return(result);
            }

            var edges = await GetEdges();

            if (edges.Count == 0)
            {
                return(result);
            }

            var ids = _pathFinderService.FindShortestPath(nodes.Select(x => x.Id).ToArray(), edges.Select(x => new Guid[] { x.FromId, x.ToId }).ToList(), model.FromId, model.ToId);

            var parts = await _contractPartRepo.GetAll(ids);

            result = parts.Select(x => new ContractPartViewModel()
            {
                Id      = x.Id,
                Name    = x.Name,
                Address = x.Address,
                Phone   = x.Phone
            })
                     .OrderBy(x => Array.IndexOf(ids, x.Id))
                     .ToList();

            return(result);
        }
Exemple #2
0
        public async Task <List <TViewModel> > GetAll()
        {
            var entities = await Repo.GetAll();

            return(entities.Select(MapToModel).ToList());
        }