protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Session["enrolledList"] = new List <Academic.DbEntities.User.Users>(); var user = Page.User as CustomPrincipal; if (user != null) { using (var classHelper = new DbHelper.Classes()) using (var helper = new DbHelper.User()) { //ListView1.DataSource = helper.ListAllUsers(user.SchoolId, 100, 1); //ListView1.DataBind(); var list = helper.ListAllUsers(user.SchoolId, 100, 1); list.AddRange(list); grdNotEnrolled.DataSource = list; grdNotEnrolled.DataBind(); list.RemoveRange(0, 4); //var enrolledList =classHelper.ListUsersOfSubjectSession() grdEnrolled.DataSource = list; grdEnrolled.DataBind(); } } } }
private void LoadClasses(Academic.DbEntities.Session session) { //classes //var dict = helper.ListClassesForNextSession(user.SchoolId, sessionPosition); using (var usrHelper = new DbHelper.User()) { var teacherRoleId = usrHelper.GetRole(Academic.DbHelper.DbHelper.StaticValues.Roles.Teacher) .Id; var noticeText = " <img src = '/Content/Icons/Notice/Warning_Shield_16px.png'/> " + "<span style='backgroundcolor=darkslategrey;'>Teacher not assigned yet.</span>"; var rcs = session.RunningClasses.Where(x => !(x.Void ?? false)); var dict = rcs.GroupBy(x => x.ProgramBatch.Program); foreach (var program in dict) { var uc = (ProgramClassesUc) Page.LoadControl("~/Views/Academy/Session/ProgramClassesUc.ascx"); uc.LoadData(program, teacherRoleId, noticeText); pnlListing.Controls.Add(uc); } } }
void UpdateLoginTime(int userId) { using (var helper = new DbHelper.User()) { helper.UpadateUsersLoginTime(userId); } }
public void LoadOnlineUsers() { using (var helper = new DbHelper.User()) { var users = helper.GetOnlineUsers(UserId, SchoolId); DataList1.DataSource = users; DataList1.DataBind(); if (users.Any()) { lblEmptyOnlineUsers.Visible = false; } } }
protected void Page_Load(object sender, EventArgs e) { using (var helper = new DbHelper.User()) { var user = User as CustomPrincipal; if (user != null) { var cats = helper.ListAllUsers(); ListView1.DataSource = cats; ListView1.DataBind(); } } }
private void LoadDivisions() { using (var helper = new DbHelper.User()) { CheckBoxList1.Items.Clear(); var divId = (cmbSchool.SelectedValue == "") ? 0 : Convert.ToInt32(cmbSchool.SelectedValue); //var divs = helper.GetDivisionsForCombo(divId); //foreach (var division in divs) //{ // CheckBoxList1.Items.Add(new ListItem(division.Name, division.Id.ToString())); //} } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { var user = Page.User as CustomPrincipal; if (user != null) { hidSchoolId.Value = user.SchoolId.ToString(); using (var helper = new DbHelper.User()) { ListView1.DataSource = helper.ListAllUsers(user.SchoolId, 20, 1); ListView1.DataBind(); } } } }
void LoadUsersList() { var user = Page.User as CustomPrincipal; if (user != null) { using (var helper = new DbHelper.User()) { var roleId = Convert.ToInt32(cmbRole.SelectedValue); var inRole = helper.ListUsersInRole(user.SchoolId, roleId, user.Id); lstAsg.DataSource = inRole; lstAsg.DataBind(); lstUnAsg.DataSource = helper.ListUsersNotInRole(user.SchoolId, roleId, user.Id, inRole); lstUnAsg.DataBind(); } } }
//private void LoadUnAssignedList() //{ // using (var helper = new DbHelper.Student()) // { // List<int> assIds = new List<int>(); // foreach (ListItem item in lstAsg.Items) // { // assIds.Add(Convert.ToInt32(item.Value)); // } // lstUnAsg.Items.Clear(); // var stds = helper.GetUsersWithNoRoles(Values.Session.GetSchool(Session)); // stds.RemoveAll(x => assIds.Contains(x.Id)); // stds.ForEach(x => // { // lstUnAsg.Items.Add( // new ListItem(x.FullName, x.Id.ToString()) // ); // }); // } //} protected void btnSave_Click(object sender, EventArgs e) { if (cmbRole.SelectedIndex == 0) { valiRole.IsValid = false; } //if (lstAsg.Items.Count <= 0) //{ // valiAsgCount.IsValid = false; //} if (Page.IsValid) { List <int> list = new List <int>(); foreach (ListItem item in lstAsg.Items) { list.Add(Convert.ToInt32(item.Value)); } List <int> removedList = new List <int>(); foreach (ListItem item in lstUnAsg.Items) { removedList.Add(Convert.ToInt32(item.Value)); } var roleId = Convert.ToInt32(cmbRole.SelectedValue); using (var helper = new DbHelper.User()) { var saved = helper.SaveUsersRole(list, roleId, removedList); if (saved) { //lstUnAsg.Items.Clear(); lstAsg.Items.Clear(); //go to roles list Response.Redirect("~/Views/User/List.aspx"); } } } }
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; } } }
protected void Page_Load(object sender, EventArgs e) { var user = Page.User as CustomPrincipal; if (user != null) { lblConfirmCheck.Visible = false; lblPasswordError.Visible = false; lblQuestionSaveError.Visible = false; lblQuestionError.Visible = false; if (!IsPostBack) { txtearlierPswrd1.Text = ""; using (var helper = new DbHelper.User()) using (var file = new DbHelper.WorkingWithFiles()) { var usr = helper.GetUser(user.Id); if (usr != null) { if (SiteMap.CurrentNode != null) { var list = new List <IdAndName>() { new IdAndName() { Name = SiteMap.RootNode.Title , Value = SiteMap.RootNode.Url , Void = true }, new IdAndName() { Name = SiteMap.CurrentNode.Title //,Value = SiteMap.CurrentNode.ParentNode.Url //,Void=true } }; SiteMapUc.SetData(list); } lblName.Text = usr.FullName; lblEmail.Text = string.IsNullOrEmpty(usr.Email)? " - ":usr.Email; lblUsername.Text = usr.UserName; img.ImageUrl = file.GetImageUrl(usr.UserImageId ?? 0); ddlQuestion.DataSource = DbHelper.StaticValues.SecurityQuestion(); ddlQuestion.DataBind(); try { var progBatch = usr.Student.FirstOrDefault().StudentBatch.FirstOrDefault().ProgramBatch; //batch.ProgramBatch.NameFromBatch; phProfileInfo.Controls.Add(new Literal() { Text = "<tr><td class='data-type'>" + "Batch" + "</td><td class='data-value'>" + progBatch.Batch.Name + "</td></tr>" }); phProfileInfo.Controls.Add(new Literal() { Text = "<tr><td class='data-type'>" + "Program" + "</td><td class='data-value'>" + progBatch.Program.Name + "</td></tr>" }); phProfileInfo.Visible = true; } catch {} } } SetView(); } } }
private void SaveFile(int userId, int schoolId, Academic.DbEntities.User.Users savedUser) { using (var helper = new DbHelper.User()) using (var fileHelper = new DbHelper.WorkingWithFiles()) { //var savedUser = helper.AddOrUpdateUser(createdUser, cmbRole.SelectedValue, FileUpload1.PostedFile); //if (savedUser != null) //{ //public bool UploadToFolder(HttpPostedFileBase file) //{ // var filename = Path.GetFileName(file.FileName); // var path = Path.Combine(Server.MapPath("~/Content/Upload"), filename); // file.SaveAs(path); // return true; //} //save image //first entry to database : table File --its image if (FileUpload1.HasFile) { var imageFile = FileUpload1.PostedFile; var userPhotoFolder = fileHelper.GetUserPhotoFolder(schoolId); if (userPhotoFolder != null) { var image = new Academic.DbEntities.UserFile() { CreatedBy = userId , CreatedDate = DateTime.Now , DisplayName = Path.GetFileName(imageFile.FileName) , FileDirectory = DbHelper.StaticValues.UserImageDirectory , FileName = Guid.NewGuid().ToString() + GetExtension(imageFile.FileName, imageFile.ContentType) , FileSizeInBytes = imageFile.ContentLength , FileType = imageFile.ContentType , IsServerFile = true , SchoolId = schoolId , FolderId = userPhotoFolder.Id }; using (var fhelper = new DbHelper.WorkingWithFiles()) { GetNewGuid(fhelper, image); //TrimFirstLetterFromImageFileName(image); if (trimLoop > 9 || guidLoop > 9) { //cancel all save } else { var savedFile = fhelper.AddOrUpdateFile(image); if (savedFile != null) { //save the image with this name //var filename = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath(DbHelper.StaticValues.UserImageDirectory), image.FileName); imageFile.SaveAs(path); //add the image Id to user helper.UpdateUsersImage(savedUser.Id, savedFile.Id); } } } } else { lblSaveError.Visible = true; lblSaveError.Text = "'User Photos' directory not found."; } if (savedUser != null) { ResetTextAndCombos(); } } //else // label.Text = "Error while saving."; //} } }
protected void Page_Load(object sender, EventArgs e) { CustomDialog.OkClick += CustomDialog_OkClick; CustomDialog.CancelClick += CustomDialog_CancelClick; var user = Page.User as CustomPrincipal; if (user != null) { if (!IsPostBack) { var classId = Request.QueryString["ccId"]; if (classId != null) { var clsId = Convert.ToInt32(classId); SubjectClassId = clsId; using (var helper = new DbHelper.Classes()) using (var usrHelper = new DbHelper.User()) { var cls = helper.GetSubjectSession(clsId); if (cls != null) { var subject = cls.IsRegular ? cls.SubjectStructure.Subject : cls.Subject; ListOfSectionsInCourseUC.UserId = user.Id; ListOfSectionsInCourseUC.CourseId = subject.Id; var teacherRoleId = usrHelper.GetRole(Academic.DbHelper.DbHelper.StaticValues.Roles.Teacher) .Id; lbldNotice.Visible = !cls.ClassUsers.Any(x => x.RoleId == teacherRoleId && !(x.Void ?? false)); var clsname = cls.GetName; lblTitle.Text = clsname; lblClassName.Text = clsname; //cls.IsRegular ? cls.GetName : cls.Name; lblCourseName.Text = subject.FullName; //cls.IsRegular lblEndDate.Text = cls.EndDate == null ? " - " : cls.EndDate.Value.ToString("D"); lblStartDate.Text = cls.StartDate == null ? " - " : cls.StartDate.Value.ToString("D"); if (!(user.IsInRole("manager") || user.IsInRole("teacher"))) { var joinedClass = helper.HasTheUserAlreadyJoinedThisClass(user.Id, cls.Id); if (!(cls.SessionComplete ?? false) && cls.EnrollmentMethod == 2) { if (joinedClass != null) { lblJoinLastDate.Text = joinedClass.StartDate.HasValue ? joinedClass.StartDate.Value.ToString("D") : "-"; lblJoinLstDateTitle.Text = "Joined on"; SetEnrollDialog(false); btnEnroll.Text = "Remove enrolment"; btnEnroll.Visible = true; } else if ((cls.JoinLastDate ?? DateTime.MaxValue.Date) >= DateTime.Now.Date) { lblJoinLastDate.Text = cls.JoinLastDate.HasValue ? cls.JoinLastDate.Value.ToString("D") : "-"; SetEnrollDialog(true); btnEnroll.Visible = true; } //lnkEnrollNow.NavigateUrl = ""; } //else if (joinedClass!=null && !(cls.SessionComplete ?? false)) //{ //} } else { lblJoinLastDate.Text = cls.JoinLastDate == null ? " - " : cls.JoinLastDate.Value.ToString("D"); } lnkViewCourse.Visible = true; lnkViewCourse.NavigateUrl = "~/Views/Course/Section/?SubId=" + subject.Id; hidOrderby.Value = "name"; LoadSitemap(cls); } } } } } }
//protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) //{ // var username = CreateUserWizard1.UserName; // var password = CreateUserWizard1.Password; // var email = CreateUserWizard1.Email; // var que = CreateUserWizard1.Question; // var ans = CreateUserWizard1.Answer; // var user = new Academic.DbEntities.User.Users() // { // UserName = CreateUserWizard1.UserName // , // Password = CreateUserWizard1.Password // , // Email = CreateUserWizard1.Email // , // SecurityQuestion = CreateUserWizard1.Question // , // SecurityAnswer = CreateUserWizard1.Answer // }; // using (var helper = new DbHelper.CustomAccount()) // { // var success = helper.Register(user); // if (success) // UserLogin(user); // } //} public void UserLogin(Users viewModel) { using (var acchelper = new DbHelper.CustomAccount()) { //if (Membership.ValidateUser(viewModel.UserName, viewModel.Password)) if (acchelper.CheckUser(viewModel.UserName, viewModel.Password)) { using (var acaHelper = new DbHelper.AcademicYear()) using (var helper = new DbHelper.User()) { var user = helper.Users.First(u => u.UserName == viewModel.UserName); CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel(); serializeModel.Id = user.Id; serializeModel.FirstName = user.FirstName; serializeModel.LastName = user.LastName; serializeModel.SchoolId = user.SchoolId ?? 0; var sess = acaHelper.GetCurrentSession(); if (sess != null) { serializeModel.AcademicYearId = sess.AcademicYearId; serializeModel.SessionId = sess.Id; } JavaScriptSerializer serializer = new JavaScriptSerializer(); string userData = serializer.Serialize(serializeModel); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, //viewModel.Email, viewModel.UserName, DateTime.Now, DateTime.Now.AddMinutes(15), false, userData); string encTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); Response.Cookies.Add(faCookie); //FormsAuthentication.set //return RedirectToAction("Index", "Home"); string returnUrl = Request.QueryString["ReturnUrl"] as string; if (returnUrl != null) { //if (returnUrl.Contains("DashBoard%2fStudent") && roles.Contains("student")) //{ //} Response.Redirect(returnUrl); } else { //Response.Redirect("~/ViewsSite/Default.aspx"); Response.Redirect("~/ViewsSite/User/Dashboard/Dashboard.aspx"); } } } } }
protected void Page_Load(object sender, EventArgs e) { CustomDialog.OkClick += CustomDialog_OkClick; CustomDialog.CancelClick += CustomDialog_CancelClick; var user = Page.User as CustomPrincipal; if (user != null) { if (!IsPostBack) { var isManager = user.IsInRole(DbHelper.StaticValues.Roles.Manager); var isTeacher = user.IsInRole(DbHelper.StaticValues.Roles.Teacher); if (!isTeacher && !isManager) { Response.Redirect("~/"); return; } SetMarkCompletionDialog(); var edit = (Session["editMode"] as string) == "1"; var classId = Request.QueryString["ccId"]; if (classId != null) { var clsId = Convert.ToInt32(classId); SubjectClassId = clsId; using (var helper = new DbHelper.Classes()) using (var usrHelper = new DbHelper.User()) { var cls = helper.GetSubjectSession(clsId); if (cls != null) { var teacherRoleId = usrHelper.GetRole(Academic.DbHelper.DbHelper.StaticValues.Roles.Teacher) .Id; lbldNotice.Visible = !cls.ClassUsers.Any(x => x.RoleId == teacherRoleId && !(x.Void ?? false)); //lblStartDate.Text =cls.StartDate==null?" - ": cls.StartDate.Value.ToString("D"); //lblEndDate.Text = cls.EndDate==null?" - ":cls.EndDate.Value.ToString("D"); var clsname = cls.GetName; var coursefullname = cls.GetCourseFullName; lblTitle.Text = clsname; if (cls.SessionComplete ?? false) { imgIndicate.ToolTip = "Complete"; imgIndicate.Visible = true; } else if (cls.StartDate <= DateTime.Now && cls.EndDate >= DateTime.Now) { imgIndicate.Visible = true; imgIndicate.ToolTip = "Active"; imgIndicate.ImageUrl = "~/Content/Icons/Start/active_icon_10px.png"; } else { imgIndicate.Visible = true; imgIndicate.ToolTip = "Due"; imgIndicate.ImageUrl = "~/Content/Icons/Watch/alarm_clock_14px.png"; } lblEnrollmentMethod.Text = cls.EnrollmentMethod == 0 ? "Auto" : (cls.EnrollmentMethod == 1) ? "Manual" : "Self"; var autoEnrollment = cls.EnrollmentMethod == 0; var curTeach = helper.IsTheUserCurrentlyTeacher(user.Id, cls.IsRegular ? cls.SubjectStructure.SubjectId : cls.SubjectId ?? 0); if (edit && (isManager || curTeach) && !(cls.SessionComplete ?? false)) { lnkMarkCompletion.Visible = true; lnkEnrollStudents.Visible = (!autoEnrollment || isManager);//&& (isTeacher || isManager); lnkEnrollTeachers.Visible = isManager; } hidOrderby.Value = autoEnrollment ? "crn" : "name"; LoadSitemap(cls); var from = Request.QueryString["from"]; lnkReport.NavigateUrl = "~/Views/Report/?ccId=" + cls.Id + "&from=" + from; lnkEnrollStudents.NavigateUrl = "~/Views/Class/Enrollment/Enrollment.aspx?ccId=" + hidSubjectSessionId.Value + "&type=student"; lnkEnrollTeachers.NavigateUrl = "~/Views/Class/Enrollment/Enrollment.aspx?ccId=" + hidSubjectSessionId.Value + "&type=teacher"; lblClassName.Text = clsname; //cls.IsRegular ? cls.GetName : cls.Name; lblCourseName.Text = coursefullname; //cls.IsRegular //? cls.SubjectStructure.Subject.FullName //: cls.Subject.FullName; lblEndDate.Text = cls.EndDate == null ? " - " : cls.EndDate.Value.ToString("D"); lblStartDate.Text = cls.StartDate == null ? " - " : cls.StartDate.Value.ToString("D"); //grouping //var grp = "No grouping"; //if (cls.HasGrouping) //{ // grp = ""; // cls.SubjectClassGrouping.ToList().ForEach(c => // { // grp += cls.Name + ", "; // }); // grp = grp.TrimEnd(new char[] { ',' }); //} //lblGrouping.Text = grp; //ListView1.DataSource = helper.ListSubjectSessionEnrolledUsers(clsId); //ListView1.DataSource = helper.ListEnrolledUsers(clsId); // ListView1.DataBind(); } } } } } }
public void UserLogin(Users viewModel) { using (var acchelper = new DbHelper.CustomAccount()) { //if (Membership.ValidateUser(viewModel.UserName, viewModel.Password)) var user = acchelper.GetUser(viewModel.UserName, viewModel.Password); if (user != null) { using (var acaHelper = new DbHelper.AcademicYear()) using (var helper = new DbHelper.User()) { //var user = foundUser;//helper.Users.First(u => u.UserName == viewModel.UserName); CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel(); serializeModel.Id = user.Id; serializeModel.UserName = user.UserName; serializeModel.FirstName = user.FirstName; serializeModel.LastName = user.LastName; serializeModel.SchoolId = user.SchoolId ?? 0; serializeModel.TestString = "kkkkk"; var sess = acaHelper.GetCurrentSession(); if (sess != null) { serializeModel.AcademicYearId = sess.AcademicYearId; serializeModel.SessionId = sess.Id; } JavaScriptSerializer serializer = new JavaScriptSerializer(); string userData = serializer.Serialize(serializeModel); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, //viewModel.Email, viewModel.UserName, DateTime.Now, DateTime.Now.AddMinutes(15), false, userData); string encTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); Response.Cookies.Add(faCookie); //var reurl = FormsAuthentication.GetRedirectUrl(viewModel.UserName, true); //if (!string.IsNullOrEmpty(reurl)) //{ // UpdateLoginTime(user.Id); // //FormsAuthentication.RedirectFromLoginPage(user.UserName, true); // Response.Redirect(reurl); //} //else { //FormsAuthentication.set //return RedirectToAction("Index", "Home"); string returnUrl = Request.QueryString["ReturnUrl"] as string; if (returnUrl != null) { //if (returnUrl.Contains("DashBoard%2fStudent") && roles.Contains("student")) //{ //} UpdateLoginTime(user.Id); var qs = Request.QueryString.ToString().Replace("ReturnUrl=", ""); var queries = qs.Split(new char[] { '&' }); var i = 0; foreach (var q in queries) { if (i > 0) { returnUrl += "&" + q; } i++; } Response.Redirect(returnUrl); } else { //Response.Redirect("~/ViewsSite/Default.aspx"); UpdateLoginTime(user.Id); Response.Redirect("~/"); } } } } } }
private void LoadData() { var rc = Request.QueryString["rcId"]; var rcId = Convert.ToInt32(rc ?? "0"); using (var usrHelper = new DbHelper.User()) using (var helper = new DbHelper.Classes()) { var rcls = helper.GetRunningClass(rcId); if (rcls != null) { LoadSitemap(rcls); lblProgramBatchName.Text = rcls.ProgramBatch.NameFromBatch;//+" "+ lblAcademicSessionName.Text = rcls.AcademicYear.Name + " - " + rcls.Session.Name; lblYearSubYearName.Text = rcls.Year.Name + " - " + rcls.SubYear.Name; lblTitle.Text = rcls.ProgramBatch.NameFromBatch + " : " + lblYearSubYearName.Text; var teacherRoleId = usrHelper.GetRole(Academic.DbHelper.DbHelper.StaticValues.Roles.Teacher) .Id; foreach (var sub in rcls.SubjectClasses.Where(x => !(x.Void ?? false))) { var teacherPresent = sub.ClassUsers.Any(x => x.RoleId == teacherRoleId && !(x.Void ?? false)); var link = new HyperLink() { NavigateUrl = "~/Views/Class/CourseClassDetail.aspx?ccId=" + sub.Id, CssClass = "list-group-item" }; var lbl = new Label() { Text = sub.GetCourseFullName + "<br />", //CssClass = "link" }; link.Controls.Add(lbl); if (!teacherPresent) { var noticeText = " <img src = '/Content/Icons/Notice/Warning_Shield_16px.png'/> " + "Teacher is not assigned to this class yet. Please assign teacher(s).<br/>"; var literal = new Literal() { Text = noticeText, }; link.Controls.Add(literal); //link.Text += noticeText; } //var notice = new Literal() //{ // Text = " <img src = '/Content/Icons/Notice/Warning_Shield_16px.png'/> " + // "Teacher is not assigned to this class yet. Please assign teacher(s).<br/>", //}; // <asp:Image ID="imgNotice" runat="server" ImageUrl="~/Content/Icons/Notice/Warning_Shield_16px.png" /> //Teacher is not assigned to this class yet. Please assign teacher(s). pnlSubjects.Controls.Add(link); //pnlSubjects.Controls.Add(notice); //pnlSubjects.Controls.Add(new Literal() //{ // Text = "<br/>" //}); } } } }
private void LoadData() { if (UserId > 0) using (var helper = new DbHelper.User()) { var userId = UserId; var us = helper.GetUser(userId); if (us != null) { //tx.Text = us.FullName; //txtPageTitle.Text = "User Detail"; txtCity.Text = us.City; txtCountry.Text = us.Country; txtDOB.Text = us.DOB.HasValue ? us.DOB.Value.ToShortDateString() : ""; txtEmail.Text = us.Email; txtFirstName.Text = us.FirstName; if (us.GenderId != null) cmbGender.SelectedValue = us.GenderId.ToString();// != null ? us.Gender.Name : ""; txtLastName.Text = us.LastName; txtMidName.Text = us.MiddleName; txtPhone1.Text = us.Phone; txtUserName.Text = us.UserName; //txtStreet.Text = us.; txtPassword.Text = us.Password; var role = us.UserRoles.FirstOrDefault(); if (role != null) { ddlRole.SelectedValue = role.RoleId.ToString(); } if (us.UserImage != null) { var images = new List<FileResourceEventArgs>() { new FileResourceEventArgs() { Id = us.UserImageId??0, Visible = true, FileDisplayName = us.UserImage.DisplayName, FilePath = us.UserImage.FileDirectory+us.UserImage.FileName, FileType = us.UserImage.FileType, FileSizeInBytes = us.UserImage.FileSizeInBytes, IconPath = us.UserImage.FileDirectory+us.UserImage.FileName, IsConstantAndNotEditable = false, LocalId = "1" } }; FilesDisplay.SetInitialValues(images); } //lnkImage.NavigateUrl = us.UserImage != null // ? us.UserImage.FileDirectory + us.UserImage.FileName // : ""; //imgPhoto.ImageUrl = lnkImage.NavigateUrl != "" ? lnkImage.NavigateUrl : // "~/Content/Icons/Users/user-male-52px.png"; //imgPhoto.AlternateText = "Image not found"; } } }
protected void btnSave_Click(object sender, EventArgs e) { var user = Page.User as CustomPrincipal; if (user != null) { using (var fileHelper = new DbHelper.WorkingWithFiles()) using (var helper = new DbHelper.User()) { if (helper.DoesUserNameExist(user.SchoolId,UserId, txtUserName.Text)) { valiUserName.ErrorMessage = "Username already exists"; valiUserName.IsValid = false; } if (Page.IsValid) { var dob = DateTime.MinValue; try { dob = Convert.ToDateTime(txtDOB.Text); } catch { } var date = DateTime.Now.Date; var createdUser = new Academic.DbEntities.User.Users() { SchoolId = user.SchoolId, City = txtCity.Text, Country = txtCountry.Text, CreatedDate = date, Email = txtEmail.Text, FirstName = txtFirstName.Text, MiddleName = txtMidName.Text, LastName = txtLastName.Text, IsActive = true, IsDeleted = false, UserName = txtUserName.Text, Password = txtPassword.Text, Id = UserId, Phone = txtPhone1.Text, //Description = txtDescription.Text, }; if (cmbGender.SelectedValue!=""&& cmbGender.SelectedValue!="0") { createdUser.GenderId = Convert.ToInt32(cmbGender.SelectedValue); } if (dob != DateTime.MinValue) createdUser.DOB = dob; var userPhotoDirectory = fileHelper.GetUserPhotoFolder(user.SchoolId); if (userPhotoDirectory != null) { var files = FilesDisplay.GetFiles(); UserFile image = null; if (files != null) { if (files.Count >= 1) { var f = files[0]; //foreach (var f in files) { var fileName = Path.GetFileName(f.FilePath); image = new Academic.DbEntities.UserFile() { Id = f.Id, CreatedBy = user.Id, CreatedDate = DateTime.Now, DisplayName = f.FileDisplayName, //Path.GetFileName(imageFile.FileName) FileDirectory = DbHelper.StaticValues.UserImageDirectory, //StaticValue.UserImageDirectory FileName = fileName, //Guid.NewGuid().ToString() + GetExtension(imageFile.FileName, imageFile.ContentType) FileSizeInBytes = f.FileSizeInBytes, //imageFile.ContentLength FileType = f.FileType, //imageFile.ContentType IconPath = f.IconPath, SchoolId = user.SchoolId, IsServerFile = true, IsConstantAndNotEditable = false, FolderId = userPhotoDirectory.Id, //SubjectId = SubjectId, }; if (f.Id > 0) { image.ModifiedBy = user.Id; image.ModifiedDate = DateTime.Now; } } } } //var userRole = new Academic.DbEntities.User.UserRole() //{ // RoleId = Convert.ToInt32(ddlRole.SelectedValue), // UserId = UserId //}; var savedUser = helper.AddOrUpdateUser(createdUser, ddlRole.SelectedValue, image); if (savedUser != null) { if (UserId > 0) { Response.Redirect("~/Views/User/Detail.aspx?uId=" + UserId); } else { Response.Redirect("List.aspx"); } } } else { //show error of "Folder unable to find" lblSaveStatus.Text = "'User Photos' directory not found."; lblSaveStatus.Visible = true; } } } } }
private void LoadData() { var user = Page.User as CustomPrincipal; if (user != null) { using (var helper = new DbHelper.User()) { var uId = Request.QueryString["uId"]; var userId = Convert.ToInt32(uId); var us = helper.GetUser(userId); if (us == null) { ReturnToHomePage(); return; } LoadSitemap(us); lblHeading.Text = us.FullName; lblPageTitle.Text = "User Detail"; lblCity.Text = string.IsNullOrEmpty(us.City)?"-":us.City; lblCountry.Text = string.IsNullOrEmpty(us.Country)?"-":us.Country; lblDOB.Text = us.DOB.HasValue ? us.DOB.ToString() : "-"; lblEmail.Text = string.IsNullOrEmpty(us.Email)?"-":us.Email; lblFirstName.Text = us.FirstName; lblGender.Text = us.Gender != null ? us.Gender.Name : "-"; lblLastName.Text = string.IsNullOrEmpty(us.LastName)?"-":us.LastName; lblMidName.Text = string.IsNullOrEmpty(us.MiddleName)?"-":us.MiddleName; lblPhone.Text = string.IsNullOrEmpty(us.Phone)?"-":us.Phone; lblUserName.Text = us.UserName; //lblStreet.Text = us.; var role = us.UserRoles.Select(x => x.Role.DisplayName).ToList(); var rl = ""; foreach (var r in role) { rl += r + ", "; } rl = rl.TrimEnd(new char[] { ',', ' ' }); rl = rl.TrimEnd(new char[] { ',', ' ' }); lblRole.Text = rl; lnkImage.NavigateUrl = us.UserImage != null ? us.UserImage.FileDirectory + us.UserImage.FileName : ""; imgPhoto.ImageUrl = lnkImage.NavigateUrl != ""?lnkImage.NavigateUrl: "~/Content/Icons/Users/user-male-52px.png"; imgPhoto.AlternateText = "Image not found"; var manager = user.IsInRole(DbHelper.StaticValues.Roles.Manager); var edit = (Session["editMode"] as string) == "1"; if (manager && edit) { lnkEdit.Visible = true; lnkDeelete.Visible = true; lnkEdit.NavigateUrl = "~/Views/User/Create.aspx?uId=" + us.Id; lnkDeelete.NavigateUrl = ""; } else { lnkEdit.Visible = false; lnkDeelete.Visible = false; } } } }
public bool UpdateSchoolInfoInCookie(CustomPrincipal user, int schoolId) { try { using (var acchelper = new DbHelper.CustomAccount()) { //if (Membership.ValidateUser(viewModel.UserName, viewModel.Password)) //if (acchelper.CheckUser(viewModel.UserName, viewModel.Password)) //{ //Response.Cookies.Remove(FormsAuthentication.FormsCookieName); using (var acaHelper = new DbHelper.AcademicYear()) using (var helper = new DbHelper.User()) { //var user = helper.Users.First(u => u.UserName == userName); CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel(); serializeModel.Id = user.Id; serializeModel.FirstName = user.FirstName; serializeModel.LastName = user.LastName; serializeModel.SchoolId = schoolId; var sess = acaHelper.GetCurrentSession(); if (sess != null) { serializeModel.AcademicYearId = sess.AcademicYearId; serializeModel.SessionId = sess.Id; } //var acaId = acaHelper.GetCurrentAcademicYear(user.SchoolId); //if (acaId != null) //{ // serializeModel.AcademicYearId = acaId.Id; // var sess = acaHelper.GetCurrentSession(acaId.Id); // if (sess != null) // { // serializeModel.SessionId = sess.Id; // } // //else // //{ // // serializeModel.SessionId = 0; // //} //} JavaScriptSerializer serializer = new JavaScriptSerializer(); string userData = serializer.Serialize(serializeModel); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, //viewModel.Email, user.UserName, DateTime.Now, DateTime.Now.AddMinutes(15), false, userData); string encTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); Response.Cookies.Set(faCookie);//.Add(faCookie); //Response.Cookies[FormsAuthentication.FormsCookieName]= faCookie; /* //FormsAuthentication.set * //return RedirectToAction("Index", "Home"); * string returnUrl = Request.QueryString["ReturnUrl"] as string; * if (returnUrl != null) * { * //if (returnUrl.Contains("DashBoard%2fStudent") && roles.Contains("student")) * //{ * * //} * Response.Redirect(returnUrl); * } * else * { * Response.Redirect("~/ViewsSite/Default.aspx"); * }*/ } //} } return(true); } catch (Exception exee) { return(false); } }
private void SaveFile(int userId, Academic.DbEntities.User.Users savedUser) { using (var helper = new DbHelper.User()) { //var savedUser = helper.AddOrUpdateUser(createdUser, cmbRole.SelectedValue, FileUpload1.PostedFile); //if (savedUser != null) //{ //public bool UploadToFolder(HttpPostedFileBase file) //{ // var filename = Path.GetFileName(file.FileName); // var path = Path.Combine(Server.MapPath("~/Content/Upload"), filename); // file.SaveAs(path); // return true; //} //save image //first entry to database : table File --its image if (FileUpload1.HasFile) { var imageFile = FileUpload1.PostedFile; var image = new Academic.DbEntities.UserFile() { CreatedBy = userId , CreatedDate = DateTime.Now , DisplayName = Path.GetFileName(imageFile.FileName) , FileDirectory = DbHelper.StaticValues.UserImageDirectory , FileName = Guid.NewGuid().ToString() + GetExtension(imageFile.FileName, imageFile.ContentType) , FileSizeInBytes = imageFile.ContentLength , FileType = imageFile.ContentType , }; using (var fhelper = new DbHelper.WorkingWithFiles()) { GetNewGuid(fhelper, image); //TrimFirstLetterFromImageFileName(image); if (trimLoop > 9 || guidLoop > 9) { //cancel all save } else { var savedFile = fhelper.AddOrUpdateFile(image); if (savedFile != null) { //save the image with this name //var filename = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath(DbHelper.StaticValues.UserImageDirectory), image.FileName); imageFile.SaveAs(path); //add the image Id to user helper.UpdateUsersImage(savedUser.Id, savedFile.Id); // return true; } } } } //} //Label label = (Label)this.Page.FindControl("lblBodyMessage"); //if (label != null) //{ if (savedUser != null) { //label.Text = "Save Successful."; //Page.Response.Redirect("List.aspx"); ResetTextAndCombos(); } //else // label.Text = "Error while saving."; //} } }