protected void btnInterested_Click(object sender, EventArgs e)
    {
        if (!Page.User.Identity.IsAuthenticated)
        {
            Response.Redirect("./login.aspx");
        }
        WebshopDataContext dc = new WebshopDataContext();
        aspnet_User user = (from ev in dc.aspnet_Users where ev.UserName.Equals(Page.User.Identity.Name) select ev).FirstOrDefault();
        ListsOfParticipant lists = (from ev in dc.ListsOfParticipants where ev.EventID == m_eventID && ev.UserID == user.UserId select ev).FirstOrDefault();

        if (lists == null)
        {
            ListsOfParticipant newLists = new ListsOfParticipant
            {
                UserID = user.UserId,
                EventID = m_eventID,
                Interested = true
            };

            dc.ListsOfParticipants.InsertOnSubmit(newLists);
            dc.SubmitChanges();
            dc.Dispose();
        }
        else if (lists.Interested == false)
        {
            //ListsOfParticipant newLists = new ListsOfParticipant
            //{
            //    lists.Interested = true
            //};
            lists.Interested = true;

            dc.ListsOfParticipants.Attach(lists, true);
            dc.SubmitChanges();

            dc.Dispose();
        }
    }
    protected void Update_Click(object sender, EventArgs e)
    {
        WebshopDataContext dc = new WebshopDataContext();

        Event event_x = ( from ev in dc.Events
                          where ev.Name.Equals(ddltIsMainEvent.SelectedItem.Text)
                          select ev).FirstOrDefault();

            event_x.Name = txtName.Text;
            event_x.StsrtDateTime = DateTime.Parse(txtEndDateTime.Text);
            event_x.EndDateTime = DateTime.Parse(txtEndDateTime.Text);
            event_x.NOfMinimum = int.Parse(txtNoOfMin.Text);
            event_x.NOfMaximum = int.Parse(txtNoOfMax.Text);
            event_x.Conditions = txtConditions.Text;
            event_x.Location = txtLocation.Text;
            event_x.Price = decimal.Parse(txtPrice.Text);
            event_x.Description = txtDescription.Text;

            if (ddltIsMainEvent.SelectedIndex == 0)
            {
                event_x.isMainEvent = true;
            }
            else
            {
                event_x.isMainEvent = false;
                event_x.ParentEventID = (from ev in dc.Events
                                         where ev.Name.Equals(events_list.SelectedItem.Text)
                                         select ev.EventID).FirstOrDefault();
            }

            Image img = new Image
            {
                URL = txtPicture.Text
            };

            dc.Images.InsertOnSubmit(img);
            dc.SubmitChanges();

            EventImage eveimg = new EventImage
            {
                EventID = event_x.EventID,
                ImageID = img.ImageID
            };

            dc.EventImages.InsertOnSubmit(eveimg);

        dc.SubmitChanges();
    }
    protected void Delete_Click(object sender, EventArgs e)
    {
        WebshopDataContext dc = new WebshopDataContext();

        Event event_x = ( from ev in dc.Events
                         where ev.Name.Equals(events_list.SelectedItem.Text)
                         select ev).FirstOrDefault();

        IEnumerable<EventOrganization> event_organizations = ( from ev in dc.EventOrganizations
                                       where ev.EventID == event_x.EventID
                                       select ev);

        IEnumerable<EventPlacesToMeet> event_places_to_meet = (from ev in dc.EventPlacesToMeets
                                                               where ev.EventID == event_x.EventID
                                                               select ev);

        dc.Events.DeleteOnSubmit(event_x);
        dc.EventOrganizations.DeleteAllOnSubmit(event_organizations);
        dc.EventPlacesToMeets.DeleteAllOnSubmit(event_places_to_meet);
        dc.SubmitChanges();
        Response.Redirect(Request.RawUrl);
    }
    protected void Add_Click(object sender, EventArgs e)
    {
        WebshopDataContext dc = new WebshopDataContext();

        aspnet_User user = (from ev in dc.aspnet_Users where ev.UserName.Equals(Page.User.Identity.Name) select ev).FirstOrDefault();

        OrganizationManagement orgman = (from ev in dc.OrganizationManagements
                                         where ev.UserID == user.UserId
                                         select ev).FirstOrDefault();

        Event event_x = new Event
        {
            Name = txtName.Text,
            StsrtDateTime = DateTime.Parse(txtEndDateTime.Text),
            EndDateTime = DateTime.Parse(txtEndDateTime.Text),
            NOfMinimum = int.Parse(txtNoOfMin.Text),
            NOfMaximum = int.Parse(txtNoOfMax.Text),
            Conditions = txtConditions.Text,
            Location = txtLocation.Text,
            Price = decimal.Parse(txtPrice.Text),
            Description = txtDescription.Text,
            //isMainEvent = btnIsMainEvent.Checked
        };

        if (ddltIsMainEvent.SelectedIndex == 0)
        {
            event_x.isMainEvent = true;
        }
        else
        {
            event_x.isMainEvent = false;
            event_x.ParentEventID = (from ev in dc.Events
                                     where ev.Name.Equals(ddltIsMainEvent.SelectedItem.Text)
                                     select ev.EventID).FirstOrDefault();
        }

        Image img = new Image
        {
            URL = txtPicture.Text
        };

        dc.Events.InsertOnSubmit(event_x);
        dc.Images.InsertOnSubmit(img);
        dc.SubmitChanges();

        EventImage eveimg = new EventImage
        {
            EventID = event_x.EventID,
            ImageID = img.ImageID
        };

        EventOrganization event_orgainzation = new EventOrganization
        {
            EventID = event_x.EventID,
            OrgainzationID = orgman.OrganizationID
        };

        dc.EventImages.InsertOnSubmit(eveimg);
        dc.EventOrganizations.InsertOnSubmit(event_orgainzation);
        dc.SubmitChanges();
        Response.Redirect(Request.RawUrl);
    }