private void DisplayData(SessionsResult sessionInfo)
    {
        if (sessionInfo == null)
        {
            throw new ApplicationException("sesionInfo is null in DisplayData");
        }

        if (sessionInfo.SponsorId.HasValue)
        {
            sponsorId = sessionInfo.SponsorId.Value;
        }

        if (!String.IsNullOrEmpty(sessionInfo.BoxFolderIdString))
        {
            UploadToBoxMailToHrefId.Visible = true;
            UploadToBoxMailToHrefId.HRef = String.Format("mailto:{0}?subject=Attach Slides and Code Files For Upload To Your Session And Send",sessionInfo.BoxFolderEmailInAddress);
            UploadToBoxMailToHrefId.InnerText = "mailto: Custom Mailer That Attaches To Your Session For All Attendees";

            ButtonCreateMailInId.Visible = false;
            ButtonDeleteSlidesFolderId.Visible = true;
        }
        else
        {
            UploadToBoxMailToHrefId.Visible = false;
            ButtonCreateMailInId.Visible = true;
            ButtonDeleteSlidesFolderId.Visible = false;
        }

        TextBoxMaterialUrl.Text = sessionInfo.SessionsMaterialUrl ?? "";

        LabelPresenter.Text = Context.Server.HtmlDecode(CodeCampSV.Utils.GetAttendeeNameByUsername(sessionInfo.Username));
        LabelPresenterAdditional.Text = Context.Server.HtmlDecode(CodeCampSV.Utils.GetSecondaryPresentersBySessionIdString(sessionInfo.Id,sessionInfo.Username));
        TextBoxSummary.Text = Context.Server.HtmlDecode(sessionInfo.Description);
        TextBoxTitle.Text = Context.Server.HtmlDecode(sessionInfo.Title);
        TextBoxHashTags.Text = Context.Server.HtmlDecode(sessionInfo.TwitterHashTags);
        CheckBoxDoNotShowPrimarySpeaker.Checked = sessionInfo.DoNotShowPrimarySpeaker;
        CheckBoxQueueEmailNotification.Checked = sessionInfo.SessionsMaterialQueueToSend.HasValue && sessionInfo.SessionsMaterialQueueToSend.Value;
         //       TextBoxSlides.Text = sessionInfo.SessionsMaterialUrl;

        if (sessionInfo.SessionLevel_id == 1)
        {
            DropDownListLevels.SelectedIndex = 0;
        }
        else if (sessionInfo.SessionLevel_id == 2)
        {
            DropDownListLevels.SelectedIndex = 1;
        }
        else if (sessionInfo.SessionLevel_id == 3)
        {
            DropDownListLevels.SelectedIndex = 2;
        }

        TagsODS tagsODS = new TagsODS();
        List<TagsODS.DataObjectTags> tagsODSli =
            tagsODS.GetAllBySession(string.Empty, sessionsId,false);

        CheckBoxListTags.DataBind();

        foreach (ListItem li in CheckBoxListTags.Items)
        {
            foreach (TagsODS.DataObjectTags dot in tagsODSli)
            {
                if (dot.Tagname.Equals(li.Text))
                {
                    li.Selected = true;
                }
            }
        }

        if (sessionInfo.SpeakersList != null && sessionInfo.SpeakersList.Count == 1)
        {
            SpeakerHandle2Tr.Visible = false;
            SpeakerHandle3Tr.Visible = false;
        }

        if (sessionInfo.SpeakersList != null && sessionInfo.SpeakersList.Count == 2)
        {
            SpeakerHandle3Tr.Visible = false;
        }

        if (SpeakerHandle1Tr.Visible && sessionInfo.SpeakersList != null && sessionInfo.SpeakersList.Count > 0)
        {
            SpeakerName1.Text = sessionInfo.SpeakersList[0].UserFirstName  + " " +
                                  sessionInfo.SpeakersList[0].UserLastName;
            TextBoxSpeakerHandle1.Text = sessionInfo.SpeakersList[0].TwitterHandle ?? "";
            SpeakerHandle1Id.Text = sessionInfo.SpeakersList[0].AttendeeId.ToString(CultureInfo.InvariantCulture);
        }

        if (SpeakerHandle2Tr.Visible && sessionInfo.SpeakersList != null && sessionInfo.SpeakersList.Count > 1)
        {
            SpeakerName2.Text = sessionInfo.SpeakersList[1].UserFirstName + " " +
                                  sessionInfo.SpeakersList[1].UserLastName;
            TextBoxSpeakerHandle2.Text = sessionInfo.SpeakersList[1].TwitterHandle ?? "";
            SpeakerHandle2Id.Text = sessionInfo.SpeakersList[1].AttendeeId.ToString(CultureInfo.InvariantCulture);
        }

        if (SpeakerHandle3Tr.Visible && sessionInfo.SpeakersList != null && sessionInfo.SpeakersList.Count > 2)
        {
            SpeakerName3.Text = sessionInfo.SpeakersList[2].UserFirstName + " " +
                                  sessionInfo.SpeakersList[2].UserLastName;
            TextBoxSpeakerHandle3.Text = sessionInfo.SpeakersList[2].TwitterHandle ?? "";
            SpeakerHandle3Id.Text = sessionInfo.SpeakersList[2].AttendeeId.ToString(CultureInfo.InvariantCulture);
        }
    }
Example #2
0
 public void UpdateHashTag(SessionsResult sessionResult)
 {
     var rec = SessionsManager.I.Get(new SessionsQuery() {Id = sessionResult.Id}).FirstOrDefault();
     if (rec != null)
     {
         rec.TwitterHashTags = sessionResult.TwitterHashTags;
     }
     SessionsManager.I.Update(rec);
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        //FormsAuthentication.SetAuthCookie("pkellner", true);
        bool keepGoing = true;

        if (Request.QueryString["id"] != null)
        {
            Int32.TryParse((string)Request.QueryString["id"], out sessionsId);
            SessionId = sessionsId;
        }
        else
        {
            keepGoing = false;
            //keepGoing = true;
            //sessionsId = 5;
        }

        if (!IsPostBack)
        {
            if (Utils.CheckUserIsAdmin() || Utils.CheckUserIsRemovePrimarySpeaker())
            {
                DivRemovePrimarySpeakerFromSessionDisplay.Visible = true;
            }
            else
            {
                DivRemovePrimarySpeakerFromSessionDisplay.Visible = false;
            }

            _sessionsResults = SessionsManager.I.Get(new SessionsQuery()
                                                            {
                                                                Id = sessionsId,
                                                                WithSpeakers = true
                                                            }).FirstOrDefault();

            //SessionsODS sessionsODS = new SessionsODS();
            //List<SessionsODS.DataObjectSessions> sessionsLi =
            //    sessionsODS.GetByPrimaryKeySessions(sessionsId);

            //SessionsODS.DataObjectSessions sessionInfo = null;

            if (_sessionsResults != null && keepGoing)
            {
                if (Context.User.Identity.IsAuthenticated)
                {
                    if (!_sessionsResults.Username.Equals(Context.User.Identity.Name) && !CodeCampSV.Utils.CheckUserIsAdmin())
                    {
                        keepGoing = false;
                    }
                }
                else
                {
                    keepGoing = false;
                }
            }

            if (keepGoing)
            {
                if (_sessionsResults != null)
                {
                    DisplayData(_sessionsResults);
                }
            }
            else
            {
                ButtonUpdate1.Enabled = false;
                ButtonUpdate2.Enabled = false;
            }
        }
    }
    protected void CaptchaUltimateControl1_Verified(object sender, EventArgs e)
    {
        bool success = false;
        int idSessionNew = -1;
        Dictionary<string, int> tagsDictionaryByName = new Dictionary<string, int>();

        using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["CodeCampSV06"].ConnectionString))
        {
            sqlConnection.Open();
            // get list of existing categories to make sure doesn't exist already
            string sqlSelectAllCategories = "SELECT TagName,id FROM Tags";
            using (SqlCommand sqlCommandTagList = new SqlCommand(sqlSelectAllCategories, sqlConnection))
            {
                using (SqlDataReader sqlReaderTagListAll = sqlCommandTagList.ExecuteReader())
                {
                    while (sqlReaderTagListAll.Read())
                    {
                        String tagName = sqlReaderTagListAll.GetString(0).ToLower().Trim();
                        int tagId = sqlReaderTagListAll.GetInt32(1);
                        if (!tagsDictionaryByName.ContainsKey(tagName) && !String.IsNullOrEmpty(tagName))
                        {
                            tagsDictionaryByName.Add(tagName, tagId);
                        }
                    }
                }
            }
            // first see if new categories to add.

            List<string> categoriesToAdd = new List<string>();
            if (!String.IsNullOrEmpty(TextBoxAddCategories.Text))
            {
                if (TextBoxAddCategories.Text.Length < 200)
                {  // sanity check
                    char[] delimiterChars = { ',', '.', ':', ';' };
                    string[] categoriesPass1 = TextBoxAddCategories.Text.Split(delimiterChars);
                    foreach (string category in categoriesPass1)
                    {
                        if (!tagsDictionaryByName.ContainsKey(category.ToLower().Trim()) && !String.IsNullOrEmpty(category))
                        {
                            categoriesToAdd.Add(category);
                        }
                    }
                }
            }

            MembershipUser mu = Membership.GetUser();
            List<int> listTagIDs = null;

            // $$$ Broken scope, will not work.  See SessionsEdit.aspx for correct way
            // $$$ currently broken when adding sessionspeaker table, not sure why. 4/2010 PGK
            //using (TransactionScope scope = new TransactionScope())
            //{

            try
            {
                // this is the list of all tagid's we will be inserting into session
                // (need to create now so if person has new ones to insert we can do that now)
                //
                listTagIDs = new List<int>();
                if (categoriesToAdd.Count > 0)
                {
                    string sqlInsertTag =
                       "INSERT INTO  dbo.Tags(TagName) VALUES (@TagName);SELECT @@identity";
                    using (SqlCommand sqlCommandInsertTag = new SqlCommand(sqlInsertTag, sqlConnection))
                    {
                        sqlCommandInsertTag.Parameters.Add("TagName", SqlDbType.VarChar).Value = string.Empty;
                        foreach (string newCategory in categoriesToAdd)
                            if (!String.IsNullOrEmpty(newCategory))
                            {
                                sqlCommandInsertTag.Parameters["TagName"].Value = newCategory;
                                int idTag = Convert.ToInt32((Decimal)sqlCommandInsertTag.ExecuteScalar());
                                listTagIDs.Add(idTag);
                            }
                    }

                }

                int attendeeId =
                    Utils.GetAttendeesIdFromUsername(HttpContext.Current.User.Identity.Name);

                var sessionResult = new SessionsResult
                                                   {
                                                       TweetLineTweetedPreCamp = false,
                                                       TweetLineTweeted = false,
                                                       TweetLine = string.Empty,
                                                       TweetLineTweetedDate = new DateTime(1960,1,1),
                                                       Approved = true,
                                                       CodeCampYearId = Utils.GetCurrentCodeCampYear(),
                                                       //Attendeesid = attendeeId,
                                                       Createdate = DateTime.Now,
                                                       Description = TextBoxDescription.Text.Trim(),
                                                       InterentAccessRequired = CheckBoxInternetAccess.Checked,

                                                       SessionLevel_id =
                                                           Convert.ToInt32(DropDownListLevel.SelectedValue),
                                                       LectureRoomsId = Utils.RoomNotAssigned,
                                                       SessionTimesId = Utils.TimeSessionUnassigned,
                                                       Title = TextBoxTitle.Text.Trim(),
                                                       Username = HttpContext.Current.User.Identity.Name,
                                                       DoNotShowPrimarySpeaker = false,
                                                       TwitterHashTags = TextBoxHashTags.Text
                                                   };
                SessionsManager.I.Insert(sessionResult);
                idSessionNew = sessionResult.Id;

                // THIS SHOULD NOT BE USED BECAUSE IT DOES NOT CONTAIN DEFAULTS FOR NEW SESSIONPRESENTER TABLE

                const string sqlInsertSessionPresenter = "INSERT INTO  SessionPresenter (AttendeeId,SessionId) VALUES (@AttendeeId,@SessionId)";
                using (var sqlCommandInsertSessionPresenter = new SqlCommand(sqlInsertSessionPresenter, sqlConnection))
                {
                    sqlCommandInsertSessionPresenter.Parameters.Add("AttendeeId", SqlDbType.Int).Value = attendeeId;
                    sqlCommandInsertSessionPresenter.Parameters.Add("SessionId", SqlDbType.Int).Value = idSessionNew;
                    sqlCommandInsertSessionPresenter.ExecuteScalar();
                }

                foreach (ListItem item in CheckBoxListTags.Items)
                {

                    if (item.Selected)
                    {
                        String itemText = item.Text.Trim().ToLower();
                        if (tagsDictionaryByName.ContainsKey(itemText))
                        {
                            int tagId = tagsDictionaryByName[itemText];
                            listTagIDs.Add(tagId);
                        }
                        else
                        {
                            throw new ApplicationException(String.Format("problem with tag not in dictionary: {0} {1}", itemText, tagsDictionaryByName.Count));
                        }
                    }
                }

                foreach (int idTag in listTagIDs)
                {
                    SessionTagsManager.I.Insert(new SessionTagsResult
                    {
                        SessionId = idSessionNew,
                        TagId = idTag
                    });
                }
                //scope.Complete();
                success = true;
            }
            catch (Exception ee)
            {
                throw new ApplicationException(String.Format("{0} Items in dictionary: {1}", ee, tagsDictionaryByName.Count));
            }
        }
        //} // end of transaction

        CodeCampSV.Utils.CacheClear("sessions");

        if (success)
        {
            string str = "~/Sessions.aspx?id=" + idSessionNew.ToString();
            // invalidate cache for adds when we add a new user
            CodeCampSV.Utils.ClearDisplayAdCache();
            CodeCampSV.Utils.ClearCacheForSessionTags(idSessionNew);
            Response.Redirect(str);
        }
        else
        {
            LabelStatus.Text = "Error Occurred.  Session Not Submitted.";
        }
    }
 private static void UpdateSessionResultForSessionLevel(SessionsResult sessionsResult)
 {
     if (sessionsResult.SessionLevel.ToLower().StartsWith("beg"))
     {
         sessionsResult.SessionLevel_id = 1;
     }
     else if (sessionsResult.SessionLevel.ToLower().StartsWith("int"))
     {
         sessionsResult.SessionLevel_id = 2;
     }
     else if (sessionsResult.SessionLevel.ToLower().StartsWith("adv"))
     {
         sessionsResult.SessionLevel_id = 3;
     }
     else
     {
         sessionsResult.SessionLevel_id = 1;
     }
 }
        /// <summary>
        ///  only let this update some safe fields.
        /// </summary>
        /// <param name="sessionsResult"></param>
        /// <returns></returns>
        public HttpResponseMessage Put(SessionsResult sessionsResult)
        {
            HttpResponseMessage response;
            if (sessionsResult != null)
            {
                sessionsResult.Title = sessionsResult.Title.Trim();

                //if (sessionsResult.Title.StartsWith("bad"))
                //{
                //    response = Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "session started with bad so erroring!");
                //    return response;
                //}

                var session =
                    SessionsManager.I.Get(new SessionsQuery
                        {
                            Id = sessionsResult.Id
                        }).FirstOrDefault();

                if (session != null)
                {
                    UpdateSessionResultForSessionLevel(sessionsResult);
                    session.Title = sessionsResult.Title;
                    session.Description = sessionsResult.Description;
                    session.TwitterHashTags = sessionsResult.TwitterHashTags;
                    session.SessionLevel_id = sessionsResult.SessionLevel_id;

                    SessionsManager.I.Update(session);

                    response = Request.CreateResponse(HttpStatusCode.OK, sessionsResult);
                }
                else
                {
                    response = Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed,
                                                           "No SessionId Found For Update");
                }
            }
            else
            {
                response = Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "SessionResult passed in is null.  Not continuing");
                //    return response;
            }

            return response;
        }
        // POST INSERT rest/session
        public HttpResponseMessage Post(SessionsResult sessionsResult)
        {
            HttpResponseMessage response;
            //string loggedInUsername = "";
            bool sessionAccepted = false;
            int attendeesId = -1;

            if (!User.Identity.IsAuthenticated || String.IsNullOrEmpty(User.Identity.Name))
            {
                response = Request.CreateErrorResponse(HttpStatusCode.Forbidden,
                                                       "Can not create session without being logged in");
            }
            else if (sessionsResult == null)
            {
                response = Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed,
                                                       "no session values passed in");
            }
            else
            {
                //loggedInUsername = User.Identity.Name;
                sessionsResult.Title = sessionsResult.Title.Trim();
                var attendeeRec =
                    AttendeesManager.I.Get(new AttendeesQuery() {Id = sessionsResult.LoggedInUserAttendeeId})
                                    .FirstOrDefault();
                if (attendeeRec != null)
                {
                    attendeesId = attendeeRec.Id;
                    // must have PresentationApprovalRequired set to false (not null) for preapproval
                    if (attendeeRec.PresentationApprovalRequired.HasValue &&
                        attendeeRec.PresentationApprovalRequired.Value == false)
                    {
                        sessionAccepted = true;
                    }
                }

                string message;
                bool canPresent = Utils.GetSpeakerCanPresent(attendeesId, out message);
                if (canPresent)
                {
                    UpdateSessionResultForSessionLevel(sessionsResult);
                    var session = new SessionsResult()
                        {
                            Createdate = DateTime.UtcNow,
                            CodeCampYearId = Utils.CurrentCodeCampYear,
                            Title = sessionsResult.Title,
                            Description = sessionsResult.Description,
                            SessionLevel_id = sessionsResult.SessionLevel_id,
                            TwitterHashTags = sessionsResult.TwitterHashTags,
                            Approved = sessionAccepted,
                            LectureRoomsId = Utils.RoomNotAssigned,
                            SessionTimesId = Utils.TimeSessionUnassigned,
                        };
                    SessionsManager.I.Insert(session);
                    response = Request.CreateResponse(HttpStatusCode.OK, session);
                }
                else
                {
                    response = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "session submission not allowed");
                }
            }

            return response;
        }