public IActionResult Get(int id) { var peer = this.peerService.GetPeer(id); if (peer == null) { return(new NotFoundResult()); } var cow = new CooperatingWorker() { Skills = peer.Skills, TasksUrl = peer.TasksUrl, CapacityUrl = peer.CapacityUrl }; return(new JsonResult(new { cooperatingWorkers = cow }, StatementOfWork.SerializerSettings)); }
internal WorkerPeer CreatePeer(CooperatingWorker cow) { var workerPeer = new WorkerPeer { Id = worker.GetNextTaskId(), TasksUrl = cow.TasksUrl, CapacityUrl = cow.CapacityUrl }; if (this.worker.Peers.TryAdd(workerPeer.Id, workerPeer)) { return(workerPeer); } else { return(null); } }
public IActionResult Post() { CooperatingWorker cow; using (var sr = new StreamReader(this.Request.Body)) { try { cow = CooperatingWorker.Load(sr); } catch { return(new BadRequestResult()); } } var peer = this.peerService.CreatePeer(cow); return(new CreatedAtActionResult("get", "peers", new { id = peer.Id }, null)); }