protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack == false)
     {
         using (TravelDBEntities context = new TravelDBEntities())
         {
             TravelDAL.Tour tour = new TravelDAL.Tour();
             tour = (from item in context.Tour
                     where item.IDTour == this.id
                     select item).First();
             rating.Text = tour.AverageMark.ToString();
             views.Text = ((int)(tour.NumberOfPageVisits + 1)).ToString();
             rates.Text = Application["tourvote" + id.ToString()].ToString();
             visits = (int)tour.NumberOfPageVisits + 1;
             Application.Lock();
             tour.NumberOfPageVisits = visits;
             context.SaveChanges();
             Application.UnLock();
             string[] i = Request.Cookies.AllKeys;
             if (i.Contains("tourvote" + id.ToString()) && Request.Cookies["tourvote" + id.ToString()].Expires < DateTime.Now)
             {
                 //UpdateButton.Visible = false;
                 UpdateLabel.Visible = true;
             }
             else
             {
                 //UpdateButton.Visible = true;
                 UpdateLabel.Visible = false;
             }
         }
     }
 }
 protected void Button1_Click(object sender, EventArgs e)
 {
     int[] mTours;
     TravelDAL.Tour obj = new TravelDAL.Tour();
     mTours = ListBox1.GetSelectedIndices();
     using (TravelDBEntities context = new TravelDBEntities())
     {
         foreach (int m in mTours)
         {
             EntityKey key = new EntityKey("TravelDBEntities.Tour", "IDTour",m + 1);
             obj = (TravelDAL.Tour)context.GetObjectByKey(key);
             if (obj != null)
             {
                 context.DeleteObject(obj);
             }
         }
         context.SaveChanges();
         Server.Transfer(Request.FilePath);
     }
 }
 protected void ButtonDone_Click(object sender, EventArgs e)
 {
     int[] mCountries;  //for lists of countries and types
     int[] mTypes;
     int[] mTours; //we have list of tours which are similar to current, we have to decide in which way it will be better to store it
     //int lastID = 0;
     TravelDAL.Tour obj = new TravelDAL.Tour();
     if (TextForName.Text != "")
     {
         using (TravelDBEntities context = new TravelDBEntities())
         {
             var num = (from item in context.Tour select item).Count();
             if (num != 0) lastID = (from item in context.Tour select item.IDTour).Max();    //getting last id from tours
             lastID++;
             if (!folderExist) CreateFolder(lastID);
         }
         obj.Name = TextForName.Text;
         obj.Program = TextForProgram.Text;
         obj.AdditionalInfo = TextForAddInfo.Text;
         obj.Price = TextForPrice.Text;
         obj.NumberOfPageVisits = 0;
         if (TextForPurchNum.Text != "")
         {
             obj.NumberOfPurchases = int.Parse(TextForPurchNum.Text);
         }
         else obj.NumberOfPurchases = 0;
         if (TextForAvgPrice.Text != "")
         {
             obj.AveragePrice = int.Parse(TextForAvgPrice.Text);
         }
         else obj.AveragePrice = 0;
         if (TextForMinPrice.Text != "")
         {
             obj.MinimalPrice = int.Parse(TextForMinPrice.Text);
         }
         else obj.MinimalPrice = 0;
         if (TextForSpecInfo.Text != "")
         {
             obj.SpecialOfferFlag = true;
             obj.SpecialOfferInfo = TextForSpecInfo.Text;
         }
         mCountries = ListofCountries.GetSelectedIndices(); //array of indexes
         mTypes = ListOfTypes.GetSelectedIndices();
         mTours = ListOfToursNames.GetSelectedIndices();
         using (TravelDBEntities context = new TravelDBEntities())
         {
             var num = (from item in context.Tour select item).Count();
             if(num != 0) lastID = (from item in context.Tour select item.IDTour).Max();    //getting last id from tours
             lastID++;
             obj.IDTour = lastID;
             obj.XmlRef = GenerateXML(obj.IDTour); // generating xml file
             foreach (int m in mTypes)
             {
                 var tip = new TravelDAL.Type{IDType = m + 1};
                 context.Type.Attach(tip);
                 obj.Type.Add(tip);
             }
             foreach (int m in mCountries)
             {
                 var coun = new Country { IDCountry = m + 1 };
                 context.Country.Attach(coun);
                 obj.Country.Add(coun);
             }
             context.Tour.AddObject(obj);
             context.SaveChanges();
         }
     }
     else
     {
         lblNewError.Text = "Enter name of tour!";
         lblNewError.Visible = true;
     }
        // else return; //i need message here, that you've forgotten to input name of tour
 }