protected void Page_Load(object sender, EventArgs e) { { var user = Page.User as CustomPrincipal; var loginUrl = "Home.aspx";//"ViewsSite/Account/Login.aspx"; if (user != null) { LoadActivityResourceSitemap(); //EarlierUc.EmptyData += EarlierUc_EmptyData; //check for school UserId = user.Id; SchoolId = user.SchoolId; lnkLoginName.Text = user.FirstName;//.UserName; if (!IsPostBack) { CoursesMenuUc1.UserId = user.Id; //using(var fileHelper = new DbHelper.WorkingWithFiles()) //CoursesUc.UserId = user.Id; //EarlierUc.UserId = user.Id; try { var editMode = Session["editMode"] as string; if (editMode == null) { //turn on edit mode //TurnOffEditMode(); Session["editMode"] = "0"; lblEditMode.Text = "Turn on edit mode"; } else { if (editMode == "1") { //turn off edit mode //TurnOnEditMode(); lblEditMode.Text = "Turn off edit mode"; } else { //turn on edit mode //TurnOffEditMode(); lblEditMode.Text = "Turn on edit mode"; } } } catch { //turn on edit mode //TurnOffEditMode(); Session["editMode"] = "0"; lblEditMode.Text = "Turn on edit mode"; } using (var usrHelper = new DbHelper.User()) using (var helper = new DbHelper.Office()) { #region Student Info var usr = usrHelper.GetUser(user.Id); var student = usr.Student; //if (student.Any()) //{ // var std = student.FirstOrDefault(); // if (std != null) // { // var stdBatch = std.StudentBatch.FirstOrDefault(); // if (stdBatch != null) // { // lblUserInfo.Text = "(" + stdBatch.ProgramBatch.NameFromBatch; // try // { // //if (user.AcademicYearId > 0) // { // var rc = usr.Classes.Select(x => x.SubjectClass) // .Where(x => x.RunningClassId != null && !(x.Void ?? false)) // .Select(x => x.RunningClass) // .FirstOrDefault(x => (x.IsActive ?? false) && !(x.Void ?? false)); // if (rc != null) // { // lblUserInfo.Text += " " + rc.GetYearAndSubYearName; // } // } // } // catch { } // lblUserInfo.Text += ")"; // } // } //} #endregion var school = helper.GetSchoolOfUser(user.Id); if (school != null) { //imgSchool.ImageUrl = "~/Content/Images/" lblSchoolName.Text = school.Name; SchoolId = user.SchoolId; var f = helper.GetSchoolImage(school.ImageId); if (f != null) { imgSchool.ImageUrl = f.FileDirectory + f.FileName; } if (Request.Url.AbsolutePath.ToLower().StartsWith("/default.aspx")) { //noticeboarduc,eventsuc, onlineusersuc //pnlBody.CssClass = "body-grey"; //earlier--not used now //middlePanel.Style.Add("border-right", "1px solid darkgrey"); //middlePanel.Style.Add("border-left", "1px solid darkgrey"); right_panel.Visible = true; } else { //pnlBody.CssClass = "body-white"; middlePanel.Style.Add("background-color", "white"); middlePanel.Attributes.Add("class", "col-md-10"); } } } //if (Request.Url.AbsolutePath.Contains("BookView") // || Request.Url.AbsolutePath.Contains("Create") // || Request.Url.AbsolutePath.Contains("Report")) //{ // right_panel.Visible = false; //} } else { var text = txtSearch.Text; var words = text.Split(new char[] { ' ' }); //var lst = words.Select(x => !(string.IsNullOrEmpty(x))); var modifiedText = ""; foreach (var w in words.Where(x => !(string.IsNullOrEmpty(x)))) { modifiedText += w + "+"; } modifiedText = modifiedText.TrimEnd('+'); if (!string.IsNullOrEmpty(modifiedText)) { Response.Redirect("~/Views/Search/?input=" + modifiedText, false); } else { txtSearch.Text = ""; } //string parameter = Request["__EVENTARGUMENT"]; // parameter //var target = Request["__EVENTTARGET"]; // btnSave //if (parameter == "txtSearch") //{ // //var converted = target.Replace(' ', '+'); // Response.Redirect("~/Views/Search/?input=" + modifiedText, false); //} } #region NOtice earlier , now commented using (var helper = new DbHelper.Notifications()) { if (user.IsInRole(DbHelper.StaticValues.Roles.Manager)) { var due = helper.GetDueClassesNotification(user.SchoolId); if (due.Any()) { lblEmptyNotice.Visible = false; //earlier //imgNotificationIcon.ImageUrl = "~/Content/Icons/Notice/Info-urgent-light-26px.png"; //var hlink = new HyperLink() //{ // Text = "Due classes, Mark completion (" + due.Count + ")", // NavigateUrl = "~/Views/Class/DueClasses.aspx" //}; var text = "Due classes, Mark completion (" + due.Count + ")"; var url = "/Views/Class/DueClasses.aspx"; var li = "<li><a href = '" + url + "'>" + text + "</a></li>"; plHolderNotice.Controls.Add(new Literal() { Text = li }); } var noTeacher = helper.GetNoTeacherInClassNotification(user.SchoolId); if (noTeacher.Any()) { lblEmptyNotice.Visible = false; //earlier //imgNotificationIcon.ImageUrl = "~/Content/Icons/Notice/Info-urgent-light-26px.png"; //var hlink = new HyperLink() //{ // //<span style='background-color:red;color:white;padding:-2px;'></span>" // Text = "Teacher not assigned to class (" + noTeacher.Count + ")", // NavigateUrl = "~/Views/Class/TeacherNotAssignedClasses.aspx" //}; //Teacher not assigned to class var url = "/Views/Class/TeacherNotAssignedClasses.aspx"; var text = "Classes without teachers (" + noTeacher.Count + ")"; var li = "<li><a href = '" + url + "'>" + text + "</a></li>"; plHolderNotice.Controls.Add(new Literal() { Text = li }); } } } //using (var nhelper = new DbHelper.Notice()) //{ // var notices = nhelper.GetNotices(user.SchoolId, user.Id); // foreach (var n in notices) // { // var nUc = // (NoticeItemUc) // Page.LoadControl("~/ViewsSite/User/ModulesUc/NoticeItemUc.ascx"); // nUc.SetData("~/Views/NoticeBoard/NoticeDetail.aspx?nId=" + n.Id, n.Title // , "posted on : " + ((n.PublishedDate == null) ? "" : n.PublishedDate.Value.ToShortDateString()) // , n.Void ?? false); // plHolderNotice.Controls.Add(nUc); // } // if (notices.Any()) // { // lblEmptyNotice.Visible = false; // } // //DataList1.DataSource = notices.Take(5).ToList(); // //DataList1.DataBind(); // var unViewed = notices.Where(x => (x.Void ?? false)).ToList(); // if (!unViewed.Any()) // { // imgNoticeIcon.ImageUrl = "~/Content/Icons/Notice/agt_announcements.png"; // //imgNoticeIndicator.Visible = false; // //lblNoticeIndication.Visible = false; // } // else // { // imgNoticeIcon.ImageUrl = "~/Content/Icons/Notice/agt_announcements_excla.png"; // //imgNoticeIndicator.Visible = true; // //lblNoticeIndication.Text = " " + unViewed.Count + " "; // } //} #endregion UpdateLoginTime(user.Id); if (user.IsInRole("manager")) { var schoolCreateUrl = "Views/Office/School/Create.aspx"; var isSchoolUrl = Request.Url.AbsolutePath.Contains(schoolCreateUrl); if (user.SchoolId <= 0 && !isSchoolUrl) { Response.Redirect("~/" + schoolCreateUrl); } SettingsUc settings = (SettingsUc)Page.LoadControl("~/ViewsSite/User/ModulesUc/SettingsUc.ascx"); //settings.UserId = user.Id; pnlSettings.Controls.Add(settings); lnkEditMode.Visible = true; //earlier settings //lnkSettingMenu.Visible = true; FileManagementMenuUc1.ShowServerMenu(); } else if (user.IsInRole("teacher")) { SettingsTeacher teachersettings = (SettingsTeacher)Page.LoadControl("~/ViewsSite/User/ModulesUc/SettingsTeacher.ascx"); //settings.UserId = user.Id; pnlSettings.Controls.Add(teachersettings); lnkEditMode.Visible = true; } } else { var path = Request.Url.AbsolutePath;//.Contains(loginUrl); if (!path.Contains(loginUrl)) { var home = path.ToLower().Contains("home.aspx"); var about = path.ToLower().Contains("about.aspx"); var contact = path.ToLower().Contains("contact.aspx"); if (!(home || about || contact)) { Response.Redirect("~/" + loginUrl); } else { left_panel.Visible = false; right_panel.Visible = true; menubar_right_text_all.Visible = false; } //if (path.Contains("Home.aspx")) //{ // Response.Redirect("~/Home.aspx"); //} //else if (path.Contains("About.aspx")) //{ // Response.Redirect("~/About.aspx"); //} //else if (path.Contains("Contact.aspx")) //{ // Response.Redirect("~/Contact.aspx"); //} //else //{ // Response.Redirect("~/" + loginUrl); //} } return; } } }
private void PopulateSchoolInfo(CustomPrincipal user) { using (var helper = new DbHelper.Office()) { var sch = helper.GetSchoolOfUser(user.Id); if (sch != null) { CKEditor1.Text = sch.Description; hidSchoolId.Value = sch.Id.ToString(); txtAddress.Text = sch.Address; txtName.Text = sch.Name; txtEmailGeneral.Text = sch.EmailGeneral; //txtEmailMarketing.Text = sch.EmailMarketing; //txtEmailSupport.Text = sch.EmailSupport; txtPhoneMain.Text = sch.PhoneMain; //txtPhoneAfterHours.Text = sch.PhoneAfterHours; hidImageId.Value = sch.ImageId.ToString(); //txtStreet.Text = sch.Street; txtWeb.Text = sch.Website; hidUserId.Value = sch.UserId.ToString(); //cmbSchoolType.SelectedValue = sch.SchoolTypeId.ToString(); var f = helper.GetSchoolImage(sch.ImageId); if (f != null) { //var fileName = Path.GetFileName(f.FilePath); var image = new FileResourceEventArgs() { Id = f.Id, //CreatedBy = user.Id //, //CreatedDate = DateTime.Now //, FileDisplayName = f.DisplayName //Path.GetFileName(imageFile.FileName) //, // FileDirectory = DbHelper.StaticValues.SchoolFileLocation //StaticValue.UserImageDirectory // , //FileName = fileName , FilePath = DbHelper.StaticValues.SchoolFileLocation + f.FileName //Guid.NewGuid().ToString() + GetExtension(imageFile.FileName, imageFile.ContentType) , FileSizeInBytes = f.FileSizeInBytes //imageFile.ContentLength , FileType = f.FileType //imageFile.ContentType , IconPath = f.IconPath , //SubjectId = SubjectId }; FilesDisplay1.SetInitialValues(new List <FileResourceEventArgs>() { image }); } } if (SiteMap.CurrentNode != null) { var list = new List <IdAndName>() { new IdAndName() { Name = SiteMap.RootNode.Title , Value = SiteMap.RootNode.Url , Void = true }, new IdAndName() { Name = sch == null?SiteMap.CurrentNode.ParentNode.Title:sch.Name , Value = SiteMap.CurrentNode.ParentNode.Url , Void = true }, new IdAndName() { Name = "Edit" } }; SiteMapUc.SetData(list); } } }