public IHttpActionResult PutClientsTable(int id, ClientsTable clientsTable)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != clientsTable.ID)
            {
                return(BadRequest());
            }

            db.Entry(clientsTable).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClientsTableExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public static string GetClientsOfOrders(string date)
        {
            DataTable table    = new DataTable();
            DateTime  dateTime = Convert.ToDateTime(date);

            // To store values from DB
            ClientsTable clientsTable;

            // Creates a SQL connection
            string strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            using (var connection = new SqlConnection(strConnString))
            {
                connection.Open();

                // Creates a SQL command
                using (var command = new SqlCommand("SELECT id_cliente, nombre_cliente, apellido_cliente, colonia_cliente, nombre_ruta, postal_cliente, telefono_cliente, movil_cliente, plano_cliente FROM View_ClientesConPedido WHERE fechaEntrega_orden = @DeliverDate", connection))
                {
                    // Loads the query results into the table
                    command.Parameters.AddWithValue("@DeliverDate", dateTime);
                    table.Load(command.ExecuteReader());
                }

                clientsTable = new ClientsTable(table);
                connection.Close();
            }

            // Filter values form DB (Remove repeated clients)
            List <Client> distinctItems = clientsTable.ClientsStoredTable.GroupBy(x => x.Id).Select(y => y.First()).ToList();

            string json = JsonConvert.SerializeObject(distinctItems);

            return(json);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ClientsTable clientsTable = db.ClientsTables.Find(id);

            db.ClientsTables.Remove(clientsTable);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "ID,LastName,FirstName,Age,Gender")] ClientsTable clientsTable)
 {
     if (ModelState.IsValid)
     {
         db.Entry(clientsTable).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(clientsTable));
 }
        public ActionResult Create([Bind(Include = "ID,LastName,FirstName,Age,Gender")] ClientsTable clientsTable)
        {
            if (ModelState.IsValid)
            {
                db.ClientsTables.Add(clientsTable);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(clientsTable));
        }
        public IHttpActionResult GetClientsTable(int id)
        {
            ClientsTable clientsTable = db.ClientsTables.Find(id);

            if (clientsTable == null)
            {
                return(NotFound());
            }

            return(Ok(clientsTable));
        }
        public IHttpActionResult PostClientsTable(ClientsTable clientsTable)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ClientsTables.Add(clientsTable);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = clientsTable.ID }, clientsTable));
        }
        private void Join(byte[] data, EndPoint sender)
        {
            if (OneShotJoin == true)
            {
                byte[] StartedAlready = new byte[1];
                StartedAlready[0] = 161;
                transport.Send(StartedAlready, sender);
            }
            else if (idCounter < 8)
            {
                idCounter++;
                if (!ClientsTable.ContainsKey(sender))
                {
                    ClientsTable.Add(sender, idCounter);
                    ClientPosition.Add(idCounter, playersInfo);
                    ClientAlive.Add(idCounter, 1);
                }
                byte[] ResponsePacketPosition = new byte[17];
                ResponsePacketPosition[0] = 2;

                byte[] id;
                byte[] joinPositionX;
                byte[] joinPositionY;
                byte[] joinPositionZ;

                id = BitConverter.GetBytes(idCounter);
                if (idCounter % 2 == 0)
                {
                    joinPositionX         = BitConverter.GetBytes(1f);
                    joinPositionY         = BitConverter.GetBytes(3.77f);
                    joinPositionZ         = BitConverter.GetBytes(-2f - spawnPositionCounter);
                    spawnPositionCounter += 2f;
                }
                else
                {
                    joinPositionX = BitConverter.GetBytes(-1.5f);
                    joinPositionY = BitConverter.GetBytes(3.77f);
                    joinPositionZ = BitConverter.GetBytes(-2f - spawnPositionCounter);
                }
                Buffer.BlockCopy(id, 0, ResponsePacketPosition, 1, 4);
                Buffer.BlockCopy(joinPositionX, 0, ResponsePacketPosition, 5, 4);
                Buffer.BlockCopy(joinPositionY, 0, ResponsePacketPosition, 9, 4);
                Buffer.BlockCopy(joinPositionZ, 0, ResponsePacketPosition, 13, 4);
                transport.Send(ResponsePacketPosition, sender);
            }
            else
            {
                byte[] tooManyPlayers = new byte[1];
                tooManyPlayers[0] = 162;
                transport.Send(tooManyPlayers, sender);
            }
        }
 public void KeepAlive()
 {
     keepAliveTimer += 0.005f;
     if (keepAliveTimer >= 3)
     {
         foreach (var item in ClientAlive)
         {
             if (item.Value == 0)
             {
                 foreach (var item2 in ClientsTable)
                 {
                     if (item.Key != item2.Value)
                     {
                         byte[] DestroyThisPlayer = new byte[5];
                         DestroyThisPlayer[0] = 88;
                         byte[] id = BitConverter.GetBytes(item.Key);
                         Buffer.BlockCopy(id, 0, DestroyThisPlayer, 1, 4);
                         transport.Send(DestroyThisPlayer, item2.Key);
                     }
                     else
                     {
                         PlayerToDestroyEndPoint = item2.Key;
                     }
                 }
                 PlayerToDestroyID = item.Key;
                 DictionaryRemover = true;
             }
         }
         if (DictionaryRemover)
         {
             ClientAlive.Remove(PlayerToDestroyID);
             ClientsTable.Remove(PlayerToDestroyEndPoint);
             ClientPosition.Remove(PlayerToDestroyID);
             //idCounter--;
             if (OneShotReady)
             {
                 ReadyCounter--;
             }
             DictionaryRemover = false;
         }
         foreach (var item in ClientsTable)
         {
             ClientAlive[item.Value] = 0;
             byte[] keepAlive = new byte[1];
             keepAlive[0] = 18;
             transport.Send(keepAlive, item.Key);
         }
         keepAliveTimer = 0;
     }
 }
        // GET: ClientsA/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ClientsTable clientsTable = db.ClientsTables.Find(id);

            if (clientsTable == null)
            {
                return(HttpNotFound());
            }
            return(View(clientsTable));
        }
        public IHttpActionResult DeleteClientsTable(int id)
        {
            ClientsTable clientsTable = db.ClientsTables.Find(id);

            if (clientsTable == null)
            {
                return(NotFound());
            }

            db.ClientsTables.Remove(clientsTable);
            db.SaveChanges();

            return(Ok(clientsTable));
        }
Beispiel #12
0
        public static string GetCloseClients(IDictionary <string, object> client, bool colony, bool rute, bool cp, string date)
        {
            DataTable table    = new DataTable();
            DateTime  dateTime = Convert.ToDateTime(date);

            Client clientObj = new Client(client);

            // To store values from DB
            ClientsTable clientsTable;

            // Creates a SQL connection
            string strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            using (var connection = new SqlConnection(strConnString))
            {
                connection.Open();

                // Creates a SQL command, default is colony search
                string sqlQuery = "SELECT id_cliente, nombre_cliente, apellido_cliente, colonia_cliente, nombre_ruta, id_ruta, postal_cliente, telefono_cliente, movil_cliente, plano_cliente, ultima_entrega" +
                                  " FROM View_ClienteRutas WHERE colonia_cliente LIKE @Place AND id_cliente != @ThisClientID AND id_cliente not in (SELECT id_cliente FROM View_ClientesConPedido WHERE fechaEntrega_orden = @Date OR fechaEntrega_orden = CAST(GETDATE() AS DATE))";
                if (colony)
                {
                    sqlQuery = "SELECT id_cliente, nombre_cliente, apellido_cliente, colonia_cliente, nombre_ruta, id_ruta, postal_cliente, telefono_cliente, movil_cliente, plano_cliente, ultima_entrega" +
                               " FROM View_ClienteRutas WHERE colonia_cliente LIKE @Place AND id_cliente != @ThisClientID AND id_cliente not in (SELECT id_cliente FROM View_ClientesConPedido WHERE fechaEntrega_orden = @Date OR fechaEntrega_orden = CAST(GETDATE() AS DATE))";
                }
                else if (rute)
                {
                    sqlQuery = "SELECT id_cliente, nombre_cliente, apellido_cliente, colonia_cliente, nombre_ruta, id_ruta, postal_cliente, telefono_cliente, movil_cliente, plano_cliente, ultima_entrega" +
                               " FROM View_ClienteRutas WHERE nombre_ruta = @Place AND id_cliente != @ThisClientID AND id_cliente not in (SELECT id_cliente FROM View_ClientesConPedido WHERE fechaEntrega_orden = @Date OR fechaEntrega_orden = CAST(GETDATE() AS DATE))";
                }
                else if (cp)
                {
                    sqlQuery = "SELECT id_cliente, nombre_cliente, apellido_cliente, colonia_cliente, nombre_ruta, id_ruta, postal_cliente, telefono_cliente, movil_cliente, plano_cliente, ultima_entrega" +
                               " FROM View_ClienteRutas WHERE postal_cliente = @Place AND postal_cliente != '' AND id_cliente != @ThisClientID AND id_cliente not in (SELECT id_cliente FROM View_ClientesConPedido WHERE fechaEntrega_orden = @Date OR fechaEntrega_orden = CAST(GETDATE() AS DATE))";
                }

                using (var command = new SqlCommand(sqlQuery, connection))
                {
                    // Loads the query results into the table
                    // Default colony parameter
                    if (colony)
                    {
                        command.Parameters.AddWithValue("@Place", clientObj.Colonia);
                    }
                    else if (rute)
                    {
                        command.Parameters.AddWithValue("@Place", clientObj.Ruta);
                    }
                    else if (cp)
                    {
                        command.Parameters.AddWithValue("@Place", clientObj.Postal);
                    }

                    command.Parameters.AddWithValue("@ThisClientID", Convert.ToInt32(clientObj.Id));
                    command.Parameters.AddWithValue("@Date", dateTime);
                    table.Load(command.ExecuteReader());
                }

                clientsTable = new ClientsTable(table);
                connection.Close();
            }

            // Filter values form DB (Remove repeated clients)
            List <Client> distinctItems = clientsTable.ClientsStoredTable.GroupBy(x => x.Id).Select(y => y.First()).ToList();

            distinctItems.Add(clientObj);

            string json = JsonConvert.SerializeObject(distinctItems);

            return(json);
        }