public Shipper GetShipper(int id)
        {
            try
            {
                var shipper = new Shipper { Id = id };
                using (var conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    var cmd = new SqlCommand("SELECT [ShipperID], [CompanyName], [Phone] FROM [dbo].[Shippers] WHERE [ShipperID] = @Id", conn);
                    cmd.Parameters.AddWithValue("@Id", id);

                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            shipper.CompanyName = reader["CompanyName"].ToString();
                            shipper.Phone = reader["Phone"].ToString();
                        }
                    }
                }
                return shipper;
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }
 public void SaveShipper(Shipper shipper)
 {
     try
     {
         repo.SaveShopper(shipper);
     }
     catch (Exception ex)
     {
         throw new FaultException(ex.Message);
     }
 }
Beispiel #3
0
 protected void ButtonSave_Click(object sender, EventArgs e)
 {
     var host = new ShipperServiceClient();
     var shipper = new Shipper
     {
         ShipperID = int.Parse(TextBoxShipperId.Text),
         CompanyName = TextBoxCompanyName.Text,
         Phone = TextBoxPhone.Text
     };
     host.SaveShipper(shipper);
 }
 public void UpdateShipper(Shipper shipper)
 {
     using (var context = new NORTHWNDEntities())
     {
         var shipperToUpdate = context.Shippers.Where(x => x.ShipperID == shipper.ShipperID).Select(x => x).FirstOrDefault();
         if (shipperToUpdate != null)
         {
             shipperToUpdate.CompanyName = shipper.CompanyName;
             shipperToUpdate.Phone = shipper.Phone;
         }
         context.SaveChanges();
     }
 }
        public void SaveShipper(Shipper shipper)
        {
            using (SqlConnection connection = new SqlConnection(_settings))
            using (SqlCommand cmd = connection.CreateCommand())
            {
                cmd.Parameters.AddWithValue("@companyName", shipper.CompanyName);
                cmd.Parameters.AddWithValue("@phone", shipper.Phone);
                cmd.Parameters.AddWithValue("@shipperID", shipper.ShipperId);

                cmd.CommandText =
                        "UPDATE Shippers SET CompanyName = @companyName, Phone = @phone WHERE ShipperID = @shipperID";
                connection.Open();
                cmd.ExecuteNonQuery();
            }
        }
        public void SaveShipper(Shipper shipper)
        {
            using (SqlConnection connection = new SqlConnection(_settings))
                using (SqlCommand cmd = connection.CreateCommand())
                {
                    cmd.Parameters.AddWithValue("@companyName", shipper.CompanyName);
                    cmd.Parameters.AddWithValue("@phone", shipper.Phone);
                    cmd.Parameters.AddWithValue("@shipperID", shipper.ShipperId);

                    cmd.CommandText =
                        "UPDATE Shippers SET CompanyName = @companyName, Phone = @phone WHERE ShipperID = @shipperID";
                    connection.Open();
                    cmd.ExecuteNonQuery();
                }
        }
Beispiel #7
0
 protected void ButtonSave_Click(object sender, EventArgs e)
 {
     var service = new ShipperServiceClient();
     var shipper = new Shipper();
     try
     {
         shipper.ID = TextBoxID.Text;
         shipper.CompanyName = TextBoxShipperName.Text;
         shipper.Phone = TextBoxShipperPhone.Text;
         service.SaveShipper(shipper);
     }
     catch (FaultException ex)
     {
         Label1.Text = "Service error: Something went wrong" + ex.Message;
     }
     catch (Exception ex)
     {
         Label1.Text = "Client error: Something went wrong" + ex.Message;
     }
 }
Beispiel #8
0
        public Shipper GetShipperById(int id)
        {
            var shipper = new Shipper();
            var queryString = "SELECT * FROM dbo.Shippers WHERE ShipperID =" + id;
            using (var connection = new SqlConnection(_connectionstring))
            {
                var command = new SqlCommand(queryString, connection);
                connection.Open();
                var reader = command.ExecuteReader();

                while (reader.Read())
                {
                    shipper.ShipperID = (int) reader["ShipperID"];
                    shipper.CompanyName = (string) reader["CompanyName"];
                    shipper.Phone = (string) reader["Phone"];
                }
                reader.Close();
            }
            return shipper;
        }
        public bool SaveShipper(Shipper shipper)
        {
            try
            {
                using (var conn = new SqlConnection(connectionString))
                {
                    var cmd = new SqlCommand("UPDATE [dbo].[Shippers] SET [CompanyName] = @CompanyName, [Phone] = @Phone WHERE [ShipperID] = @Id", conn);
                    cmd.Parameters.AddWithValue("@CompanyName", shipper.CompanyName);
                    cmd.Parameters.AddWithValue("@Phone", shipper.Phone);
                    cmd.Parameters.AddWithValue("@Id", shipper.Id);

                    conn.Open();
                    return cmd.ExecuteNonQuery() == 1;
                }
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }
        public Shipper GetShipperByID(int shipperId)
        {
            string query = "SELECT[ShipperID] ,[CompanyName] ,[Phone] FROM[NORTHWND].[dbo].[Shippers]" +
                                 "WHERE[ShipperID] =" + shipperId; //Vill bara hämta med rätt id
            var shipper = new Shipper();
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                SqlCommand command = new SqlCommand(query, connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    shipper.ShipperID = Convert.ToInt32(reader["ShipperID"].ToString());
                    shipper.CompanyName = reader["CompanyName"].ToString();
                    shipper.Phone = reader["Phone"].ToString();
                }
            }
            return shipper;
        }
Beispiel #11
0
        public Shipper GetShipperById(int id)
        {
            var shipper     = new Shipper();
            var queryString = "SELECT * FROM dbo.Shippers WHERE ShipperID =" + id;

            using (var connection = new SqlConnection(_connectionstring))
            {
                var command = new SqlCommand(queryString, connection);
                connection.Open();
                var reader = command.ExecuteReader();

                while (reader.Read())
                {
                    shipper.ShipperID   = (int)reader["ShipperID"];
                    shipper.CompanyName = (string)reader["CompanyName"];
                    shipper.Phone       = (string)reader["Phone"];
                }
                reader.Close();
            }
            return(shipper);
        }
Beispiel #12
0
 public Shipper GetShipper(int id)
 {
     var shipper=new Shipper();
     var conn = ConfigurationManager.ConnectionStrings["NORTHWND"].ConnectionString;
     using (var connection=new SqlConnection(conn))
     {
         var getShipperCommand = new SqlCommand("Select [ShipperID], [CompanyName], [Phone] from Shippers where ShipperID=@id", connection);
         getShipperCommand.Parameters.AddWithValue("@id", id);
         connection.Open();
         using (var reader = getShipperCommand.ExecuteReader())
         {
             while (reader.Read())
             {
                 shipper.ShipperID = int.Parse(reader["ShipperID"].ToString());
                 shipper.CompanyName = reader["CompanyName"].ToString();
                 shipper.Phone = reader["Phone"].ToString();
             }
         }
     }
     return shipper;
 }
Beispiel #13
0
        public Shipper GetShipperId(int shipperId)
        {
            var shipper = new Shipper();

            string queryString =
                "SELECT * FROM [dbo].[Shippers] WHERE [ShipperID] =" + shipperId;

            using (SqlConnection connection = new SqlConnection(_settings))
            {
                SqlCommand command = new SqlCommand(queryString, connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    shipper.ShipperId = int.Parse(reader["ShipperID"].ToString());
                    shipper.CompanyName = reader["CompanyName"].ToString();
                    shipper.Phone = reader["Phone"].ToString();
                }
            }
            return shipper;
        }
Beispiel #14
0
        public Shipper GetShipperId(int shipperId)
        {
            var shipper = new Shipper();

            string queryString =
                "SELECT * FROM [dbo].[Shippers] WHERE [ShipperID] =" + shipperId;

            using (SqlConnection connection = new SqlConnection(_settings))
            {
                SqlCommand command = new SqlCommand(queryString, connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    shipper.ShipperId   = int.Parse(reader["ShipperID"].ToString());
                    shipper.CompanyName = reader["CompanyName"].ToString();
                    shipper.Phone       = reader["Phone"].ToString();
                }
            }
            return(shipper);
        }
 public bool UpdateShipper(Shipper shipper)
 {
     using (var context = new NORTHWNDEntities())
     {
         try
         {
             var shipperToUpdate = context.Shippers.FirstOrDefault(x => x.ShipperID == shipper.ShipperId);
             if (shipperToUpdate != null)
             {
                 shipperToUpdate.ShipperID = shipper.ShipperId;
                 shipperToUpdate.CompanyName = shipper.CompanyName;
                 shipperToUpdate.Phone = shipper.Phone;
             }
             context.SaveChanges();
             return true;
         }
         catch (Exception)
         {
             return false;
             throw;
         }
         
     }
 }
Beispiel #16
0
        public Shipper GetShipperByID(int id)
        {
            var theShipper = new Shipper();
            var connectionString = ConfigurationManager.ConnectionStrings["NORTHWND"].ConnectionString;
            using (var conn = new SqlConnection(connectionString))
            {
                conn.Open();

                var sqlShipperCommand = new SqlCommand("SELECT * FROM Shippers WHERE ShipperID = @id", conn);
                sqlShipperCommand.Parameters.AddWithValue("@id", id);

                using (var reader = sqlShipperCommand.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        theShipper.ShipperID = (int)reader["ShipperID"];
                        theShipper.CompanyName = reader["CompanyName"].ToString();
                        theShipper.Phone = reader["Phone"].ToString(); 
                    }
                }
                conn.Close();
            }
            return theShipper;
        }
        public bool UpdateShipper(Shipper shipper)
        {
            using (var context = new NORTHWNDEntities())
            {
                try
                {
                    var updatedShipper = context.Shippers.FirstOrDefault(x => x.ShipperID == shipper.ShipperID);

                    if (updatedShipper != null)
                    {
                        updatedShipper.ShipperID = shipper.ShipperID;
                        updatedShipper.CompanyName = shipper.CompanyName;
                        updatedShipper.Phone = shipper.Phone;
                    }

                    context.SaveChanges();
                    return true;
                }
                catch (Exception ex)
                {
                    throw new FaultException($"Shipper not updated  {ex.Message}");
                }
            }
        }