private Interactuable GetIntFromId(int receiverId)
        {
            Interactuable interactuable = new Interactuable(receiverId);
            var           recursos      = api.getRelJugadorRecursoHandler().getRecursosByColonia(receiverId);
            var           destacamento  = api.getRelJugadorDestacamentoHandler().getDestacamentosByColonia(receiverId);
            var           flota         = destacamento.Where(c => c.GetVelocidad() != 0);
            var           defensas      = destacamento.Where(c => c.GetVelocidad() == 0);

            interactuable.SetFlota(flota.Cast <IDestacamento>().ToList());
            interactuable.SetDefensas(defensas.Cast <IDestacamento>().ToList());
            interactuable.SetRecursos(recursos.Cast <IResources>().ToList());
            return(interactuable);
        }
        public HttpResponseMessage Post([FromBody] InteraccionConfig intera)
        {
            if (ModelState.IsValid)
            {
                interactionHandler.LoadInteractionByName(intera.tipo);

                Interactuable requester = new Interactuable(intera.requester.id);
                Interactuable receiver  = new Interactuable(intera.receiver.id);

                if (interactionHandler.GetConfig().isReqNeedFloat())
                {
                    List <IDestacamento> flota   = new List <IDestacamento>();
                    List <IDestacamento> current = blHandler.getDestacamentosByColonia(intera.requester.id).Cast <IDestacamento>().ToList();
                    intera.requester.flota.ToList <Tupla>().ForEach((f) =>
                    {
                        var dest = current.Where(c => c.GetId() == f.id).FirstOrDefault();
                        if (dest != null)
                        {
                            dest.SetAmount(f.value);
                            flota.Add(dest);
                        }
                    });
                    requester.SetFlota(flota);
                }
                List <IResources> recurso = new List <IResources>();
                List <IResources> rlist   = blHandler.getRecursosByColonia(intera.requester.id).Cast <IResources>().ToList();

                rlist.ForEach((f) =>
                {
                    var dest = intera.requester.recurso.ToList <Tupla>().Where(c => c.id == f.GetId()).FirstOrDefault();
                    f.SetAmount(0);
                    if (dest != null && interactionHandler.GetConfig().isReqNeedRecursos())
                    {
                        f.SetAmount(dest.value);
                    }
                    recurso.Add(f);
                });
                requester.SetRecursos(recurso);

                if (interactionHandler.GetConfig().isRecNeedFloat())
                {
                    List <IDestacamento> flotaRec   = new List <IDestacamento>();
                    List <IDestacamento> currentRec = blHandler.getDestacamentosByColonia(intera.receiver.id).Cast <IDestacamento>().ToList();
                    intera.receiver.flota.ToList <Tupla>().ForEach((f) =>
                    {
                        var dest = currentRec.Where(c => c.GetId() == f.id).FirstOrDefault();
                        if (dest != null)
                        {
                            dest.SetAmount(f.value);
                            flotaRec.Add(dest);
                        }
                    });
                    receiver.SetFlota(flotaRec);
                }
                if (interactionHandler.GetConfig().isRecNeedRecursos())
                {
                    List <IResources> recursoRec = new List <IResources>();
                    List <IResources> rlistRec   = blHandler.getRecursosByColonia(intera.requester.id).Cast <IResources>().ToList();


                    rlistRec.ForEach((f) =>
                    {
                        var dest = intera.receiver.recurso.ToList <Tupla>().Where(c => c.id == f.GetId()).FirstOrDefault();
                        f.SetAmount(0);
                        if (dest != null && interactionHandler.GetConfig().isRecNeedRecursos())
                        {
                            f.SetAmount(dest.value);
                        }

                        recursoRec.Add(f);
                    });
                    receiver.SetRecursos(recursoRec);
                }
                interactionHandler.InitializeInteraction(requester, receiver);
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created);
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
        public Interactuable GetIntFromMeta(InteractuableMetadata meta)
        {
            Interactuable interactuable = new Interactuable(meta.interactuableID);

            interactuable.setCapacidad(meta.capacidad);
            if (meta.returnToBase)
            {
                interactuable.Return();
            }
            var recursos     = builder.getRelJugadorRecursoHandler().getRecursosByColonia(meta.interactuableID);
            var destacamento = builder.getRelJugadorDestacamentoHandler().getDestacamentosByColonia(meta.interactuableID);

            var recursoToAssign = new List <RelJugadorRecurso>();
            var flotaToAssign   = new List <RelJugadorDestacamento>();
            var defensaToAssign = new List <RelJugadorDestacamento>();

            foreach (var rec in meta.recursos)
            {
                int id    = -1;
                int value = -1;
                foreach (var s in rec.ToBsonDocument().ToArray())
                {
                    if (s.Name.Equals("_id"))
                    {
                        id = s.Value.ToInt32();
                    }
                    else
                    {
                        value = s.Value.ToInt32();
                    }
                }
                var recurso = recursos.Where(c => c.recurso.id == id).ToList().First();
                recurso.cantidadR = value;
                recursoToAssign.Add(recurso);
            }
            foreach (var rec in meta.flota)
            {
                int id    = -1;
                int value = -1;
                foreach (var s in rec.ToBsonDocument().ToArray())
                {
                    if (s.Name.Equals("_id"))
                    {
                        id = s.Value.ToInt32();
                    }
                    else
                    {
                        value = s.Value.ToInt32();
                    }
                }
                var flota = destacamento.Where(c => c.destacamento.id == id).ToList().First();
                flota.cantidad = value;
                flotaToAssign.Add(flota);
            }
            foreach (var rec in meta.defensa)
            {
                int id    = -1;
                int value = -1;
                foreach (var s in rec.ToBsonDocument().ToArray())
                {
                    if (s.Name.Equals("_id"))
                    {
                        id = s.Value.ToInt32();
                    }
                    else
                    {
                        value = s.Value.ToInt32();
                    }
                }
                var defensa = destacamento.Where(c => c.destacamento.id == id).ToList().First();
                defensa.cantidad = value;
                defensaToAssign.Add(defensa);
            }
            interactuable.SetDefensas(defensaToAssign.Cast <IDestacamento>().ToList());
            interactuable.SetRecursos(recursoToAssign.Cast <IResources>().ToList());
            interactuable.SetFlota(flotaToAssign.Cast <IDestacamento>().ToList());
            return(interactuable);
        }