public MapaNode Get(int id) { MapaNode mapa = blHandler.getMapa(id); if (mapa == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } return(mapa); }
public void CreateMapa(MapaNode m) { var mapaE = new Entities.MapaNode(m.nombre, m.nivel, m.cantidad, m.distance); try { ctx.MapaNode.Add(mapaE); ctx.SaveChanges(); } catch (Exception e) { throw e; } }
private int GetDistanceBetweenColony(int requester, int receiver) { int distance = 0; RelJugadorMapa from = api.getRelJugadorMapaHandler().getRelJugadorMapa(requester); RelJugadorMapa to = api.getRelJugadorMapaHandler().getRelJugadorMapa(receiver); List <MapaNode> mapas = api.getMapaNodeHandler().getAllMapas(); if (from.nivel1 != -1 && to.nivel1 != -1 && from.nivel1 != to.nivel1) { MapaNode sect = mapas.Where(c => c.nivel == 1).FirstOrDefault(); if (sect != null && sect.cantidad > 1) { distance += sect.distance * 2; } } if (from.nivel2 != -1 && to.nivel2 != -1 && from.nivel2 != to.nivel2) { MapaNode sect = mapas.Where(c => c.nivel == 2).FirstOrDefault(); if (sect != null && sect.cantidad > 1) { distance += sect.distance * 2; } } if (from.nivel3 != -1 && to.nivel3 != -1 && from.nivel3 != to.nivel3) { MapaNode sect = mapas.Where(c => c.nivel == 3).FirstOrDefault(); if (sect != null && sect.cantidad > 1) { distance += sect.distance * 2; } } if (from.nivel4 != -1 && to.nivel4 != -1 && from.nivel4 != to.nivel4) { MapaNode sect = mapas.Where(c => c.nivel == 4).FirstOrDefault(); if (sect != null && sect.cantidad > 1) { distance += sect.distance * 2; } } if (from.nivel5 != -1 && to.nivel5 != -1 && from.nivel5 != to.nivel5) { MapaNode sect = mapas.Where(c => c.nivel == 5).FirstOrDefault(); if (sect != null && sect.cantidad > 1) { distance += sect.distance * 2; } } return(distance); }
public HttpResponseMessage Post(MapaNode mapa) { if (ModelState.IsValid) { blHandler.createMapa(mapa); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, mapa); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { controller = "Admin" })); return(response); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public void UpdateMapa(MapaNode mapa) { try { var mapaE = ctx.MapaNode .Where(w => w.id == mapa.id) .SingleOrDefault(); if (mapaE != null) { mapaE.nombre = mapa.nombre; mapaE.nivel = mapa.nivel; mapaE.cantidad = mapa.cantidad; mapaE.distance = mapa.distance; ctx.SaveChangesAsync().Wait(); } } catch (Exception ex) { throw ex; } }
public HttpResponseMessage Put(int id, MapaNode mapa) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != mapa.id) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } try { blHandler.updateMapa(mapa); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public void updateMapa(MapaNode mapa) { builder.getMapaNodeHandler().UpdateMapa(mapa); }
public void createMapa(MapaNode mapa) { builder.getMapaNodeHandler().CreateMapa(mapa); }