public async Task Establish(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 exists = _repo.QueryMatchContract(model.FromId, model.ToId).Any(x => !x.Finished); if (exists) { throw new ValidationBusinessException(ValidationMessage.ContractExists); } var contract = new Contract() { FromId = model.FromId, ToId = model.ToId }; await _repo.Add(contract); await _uow.Commit(); }
public async Task Terminate(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 entity = _repo.QueryMatchContract(model.FromId, model.ToId).FirstOrDefault(); if (entity == null) { throw new ValidationBusinessException(ValidationMessage.ContractNotExists); } if (entity.Finished) { throw new ValidationBusinessException(ValidationMessage.ContractFinished); } entity.Finished = true; _repo.Update(entity); await _uow.Commit(); }
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); }
public async Task <IActionResult> FindShortestPath([FromQuery] ContractInputModel model) { return(Ok(await _service.FindShortestPath(model))); }
public async Task <IActionResult> Terminate(ContractInputModel model) { await _service.Terminate(model); return(Ok()); }
public async Task <IActionResult> Establish(ContractInputModel model) { await _service.Establish(model); return(Ok()); }
private List <ContractPartViewModel> FindShortestPath(ContractInputModel model) { return(Service.FindShortestPath(model).GetAwaiter().GetResult()); }
private void Terminate(ContractInputModel model) { Service.Terminate(model).Wait(); }
private void Establish(ContractInputModel model) { Service.Establish(model).Wait(); }