예제 #1
0
        private void cmdDeleteAd_Click(object sender, EventArgs e)
        {
            Advert selectedad = (Advert)(listboxmyad.SelectedItem);

            using (AnnonserEntities1 db = new AnnonserEntities1())
            {
                //Här görs databasanrop dvs en command med en sql fråga som läser ut just denna leverantören
                Advert advert = db.Adverts.Where(s => s.AdID == selectedad.AdID).FirstOrDefault();

                db.Adverts.Remove(advert);
                db.SaveChanges();
                MessageBox.Show("Annons borttagen");
            }
        }
예제 #2
0
        private void listboxmyad_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listboxmyad.SelectedItem != null)
            {
                Advert selectedad = (Advert)(listboxmyad.SelectedItem);
                using (AnnonserEntities1 db = new AnnonserEntities1())
                {
                    Advert advert = db.Adverts.Where(s => s.AdID == selectedad.AdID).FirstOrDefault();

                    txtAdInfo.Text   = advert.Description;
                    txtAdTitel.Text  = advert.Title;
                    txtPrice.Text    = (advert.Price).ToString();
                    txtLocation.Text = advert.Location;
                    cboCategory.Text = ar.GetCategoryName(advert.CategoryID);
                }
            }
        }
예제 #3
0
        private void cmdCreateNew_Click(object sender, EventArgs e)
        {
            using (AnnonserEntities1 db = new AnnonserEntities1())
            {
                Advert advert = new Advert();
                advert.Title       = txtAdTitel.Text;
                advert.Description = txtAdInfo.Text;
                advert.Price       = Convert.ToInt32(txtPrice.Text);
                advert.Location    = txtLocation.Text;
                advert.AdvertDate  = DateTime.Now;
                advert.CategoryID  = cboCategory.SelectedIndex;
                advert.UserID      = this.UserID;

                db.Adverts.Add(advert);
                db.SaveChanges();
                MessageBox.Show("Annons sparad");
            }
        }
예제 #4
0
        private void cmdUpdateAd_Click(object sender, EventArgs e)
        {
            Advert selectedad = (Advert)(listboxmyad.SelectedItem);

            using (AnnonserEntities1 db = new AnnonserEntities1())
            {
                //Här görs databasanrop dvs en command med en sql fråga som läser ut just denna leverantören
                Advert advert = db.Adverts.Where(s => s.AdID == selectedad.AdID).FirstOrDefault();

                advert.Title       = txtAdTitel.Text;
                advert.Description = txtAdInfo.Text;
                advert.Price       = Convert.ToInt32(txtPrice.Text);
                advert.Location    = txtLocation.Text;
                advert.AdvertDate  = DateTime.Now;
                advert.CategoryID  = cboCategory.SelectedIndex;
                db.SaveChanges();
                MessageBox.Show("Annons uppdaterad");
            }
        }