private void LoadUsers() { using (var context = new UzoneEntities()) { List<RegisteredUser> _users; _users = context.Set<RegisteredUser>().ToList(); UsersGrid.DataSource = _users; } }
protected void RadScheduler1_AppointmentDelete(object sender, SchedulerCancelEventArgs e) { using (var context = new UzoneEntities()) { Scheduler _scheduler; _scheduler = context.Schedulers.Find(e.Appointment.ID); if (_scheduler != null) { context.Schedulers.Remove(_scheduler); context.SaveChanges(); } } }
private Boolean CheckEmailAvailability(string email) { using (var context = new UzoneEntities()) { var founduser = (from ru in context.RegisteredUsers where ru.Email == email select ru); if (founduser.Any()) return false; else return true; } }
protected void LocationGrid_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); var locationID = (int)editableItem.GetDataKeyValue("EventLocationID"); using (var context = new UzoneEntities()) { EventLocation _location; _location = context.EventLocations.Find(locationID); if (_location != null && Session["currentSchoolID"] != null) { editableItem.UpdateValues(_location); context.EventLocations.Attach(_location); context.Entry(_location).State = EntityState.Modified; context.SaveChanges(); } } }
protected void LocationGrid_DeleteCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { var locationID = (int)((GridDataItem)e.Item).GetDataKeyValue("EventLocationID"); using (var context = new UzoneEntities()) { EventLocation _location; _location = context.EventLocations.Find(locationID); if (_location != null) { _location.Active = false; context.EventLocations.Attach(_location); context.Entry(_location).State = EntityState.Modified; context.SaveChanges(); } } }
protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e) { Scheduler _scheduler = new Scheduler(); _scheduler.EventStart = e.Appointment.Start; _scheduler.EventEnd = e.Appointment.End; _scheduler.EventDescription = e.Appointment.Description; _scheduler.EventSubject = e.Appointment.Subject; _scheduler.SchoolID = (long)Session["currentSchoolID"]; if (e.Appointment.Resources.FirstOrDefault() != null) _scheduler.EventLocationID = (int)e.Appointment.Resources.First().Key; using (var context = new UzoneEntities()) { context.Schedulers.Add(_scheduler); context.SaveChanges(); LoadScheduler(); } }
protected void checkEmail_Click(object sender, EventArgs e) { using (var context = new UzoneEntities()) { RegisteredUser foundUser = (from fu in context.RegisteredUsers where fu.Email == txtEmailAddress.Value select fu).FirstOrDefault(); if (foundUser != null) { rwSecurity.Style.Add("visibility", "visible"); SendEmail.Visible = true; checkEmail.Visible = false; lbSecurityQuestion.InnerText = context.LockedQuestions.Find(foundUser.LockedQuestionID).Question; } else CreateErrorMsg("The specified email address was not found. Please check and try again."); } }
protected void LocationGrid_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { var editableItem = ((GridEditableItem)e.Item); Hashtable values = new Hashtable(); editableItem.ExtractValues(values); EventLocation _location = new EventLocation(); _location.EventLocationName = values["EventLocationName"].ToString(); _location.Active = true; using (var context = new UzoneEntities()) { if (Session["currentSchoolID"] != null) { var currentSchool = (long)Session["currentSchoolID"]; _location.SchoolID = currentSchool; context.EventLocations.Add(_location); context.SaveChanges(); } } }
protected void RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e) { using (var context = new UzoneEntities()) { Scheduler _scheduler; _scheduler = context.Schedulers.Find(e.Appointment.ID); if (_scheduler != null) { _scheduler.EventStart = e.ModifiedAppointment.Start; _scheduler.EventEnd = e.ModifiedAppointment.End; _scheduler.EventDescription = e.ModifiedAppointment.Description; _scheduler.EventSubject = e.ModifiedAppointment.Subject; _scheduler.SchoolID = (long)Session["currentSchoolID"]; if (e.Appointment.Resources.FirstOrDefault() != null) _scheduler.EventLocationID = (int)e.Appointment.Resources.First().Key; context.SaveChanges(); LoadScheduler(); } } }
protected void SendEmail_Click(object sender, EventArgs e) { var typeOfForgot = Request.QueryString["forgot"]; using (var context = new UzoneEntities()) { RegisteredUser foundUser = (from fu in context.RegisteredUsers where fu.Email == txtEmailAddress.Value && fu.LockedAnswer == txtSecurityAnswer.Value select fu).FirstOrDefault(); if (foundUser != null) { if (typeOfForgot == "forgotpassword") resetAndSend(txtEmailAddress.Value); else if (typeOfForgot == "forgotusername") sendUsername(txtEmailAddress.Value); else CreateErrorMsg("There was an issue accessing your account. Please try again."); } else CreateErrorMsg("The email and security answer combination does not exist. Please try again."); } }
private Boolean UserLogin() { using (var context = new UzoneEntities()) { var founduser = (from ru in context.RegisteredUsers where ru.UserName == txtUser.Value && ru.Password == txtPassword.Value select ru); if (founduser.FirstOrDefault() != null) { Session["userName"] = founduser.First().UserName; Session["currentSchool"] = context.Schools.FirstOrDefault(x => x.SchoolID == founduser.FirstOrDefault().SchoolID).Name; Session["currentSchoolID"] = founduser.First().SchoolID; Session["isLogged"] = "true"; Session["userRole"] = founduser.First().UserRoleID; Session["timeStamp"] = DateTime.Now; return true; } else return false; } }
private void LoadResources() { using (var context = new UzoneEntities()) { if (Session["currentSchoolID"] != null) { var currentSchool = (long)Session["currentSchoolID"]; if (RadScheduler1.ResourceTypes.FirstOrDefault() == null) { List<EventLocation> _locations; _locations = context.Set<EventLocation>().Where(l => l.SchoolID == currentSchool).ToList(); ResourceType _item = new ResourceType(); _item.DataSource = _locations; _item.ForeignKeyField = "SchoolID"; _item.KeyField = "EventLocationID"; _item.TextField = "EventLocationName"; _item.Name = "Location"; RadScheduler1.ResourceTypes.Add(_item); } } } }
private Boolean CheckUsernameAvailability(string username) { using (var context = new UzoneEntities()) { var founduser = (from ru in context.RegisteredUsers where ru.UserName == username select ru); if (founduser.Any()) return false; else return true; } }
private Boolean UpdateAccount(RegisteredUser user) { try { using (var context = new UzoneEntities()) { string _currentUsername = Session["userName"].ToString(); user.UserID = context.RegisteredUsers.FirstOrDefault(c => c.UserName == _currentUsername).UserID; } using (var context = new UzoneEntities()) { context.RegisteredUsers.Attach(user); context.Entry(user).State = EntityState.Modified; context.SaveChanges(); } return true; } catch (Exception ex) { return false; } }
private void LoadSecurityQuestion() { using (var context = new UzoneEntities()) { List<LockedQuestion> _questions; _questions = context.Set<LockedQuestion>().ToList(); comboSecurityQues.DataSource = _questions; comboSecurityQues.DataBind(); } }
private void LoadSchool() { using (var context = new UzoneEntities()) { List<School> _schools; _schools = context.Set<School>().ToList(); comboSchool.DataSource = _schools; comboSchool.DataBind(); } }
private void LoadRegistration() { using (var context = new UzoneEntities()) { RegisteredUser _user = new RegisteredUser(); string _currentUsername = Session["userName"].ToString(); _user = (from ru in context.RegisteredUsers where ru.UserName == _currentUsername select ru).FirstOrDefault(); if (_user != null) { txtName.Text = _user.Name; txtUsername.Text = _user.UserName; txtPassword.Text = _user.Password; txtConfirmPass.Text = _user.Password; txtEmail.Text = _user.Email; comboSchool.SelectedValue = _user.SchoolID.ToString(); comboSecurityQues.SelectedValue = _user.LockedQuestionID.ToString(); txtSecurityAns.Text = _user.LockedAnswer; chkTerms.Checked = true; } } }
private Boolean CreateAccount(RegisteredUser user) { try { using (var context = new UzoneEntities()) { context.RegisteredUsers.Add(user); context.SaveChanges(); } return true; } catch (Exception ex) { return false; } }
private Boolean CreateSchool(School school) { try { using (var context = new UzoneEntities()) { context.Schools.Add(school); context.SaveChanges(); } return true; } catch (Exception ex) { return false; } }
private void LoadSchools(long id) { using (var context = new UzoneEntities()) { School _schools; _schools = (from sc in context.Schools where sc.SchoolID == id select sc).FirstOrDefault(); if (_schools != null) { txtFullName.Text = _schools.Name; txtAlias.Text = _schools.Alias; txtMascot.Text = _schools.Mascot; txtAddress.Text = _schools.Address; txtCity.Text = _schools.City; txtZip.Text = _schools.Zip; txtContactEmail.Text = _schools.Email; txtContactPhone.Text = _schools.Phone; comboState.SelectedValue = _schools.State; rdColorBackground.SelectedColor = ColorTranslator.FromHtml(_schools.BannerColor); rdColorPrimary.SelectedColor = ColorTranslator.FromHtml(_schools.ButtonColor); } } }
private void LoadLocations() { using (var context = new UzoneEntities()) { if (Session["currentSchoolID"] != null) { var currentSchool = (long)Session["currentSchoolID"]; List<EventLocation> _locations; _locations = context.Set<EventLocation>().Where(l => l.SchoolID == currentSchool && l.Active == true).ToList(); LocationGrid.DataSource = _locations; } else { List<EventLocation> _locations = new List<EventLocation>(); LocationGrid.DataSource = _locations; } } }
private Boolean UpdateSchool(School school) { try { using (var context = new UzoneEntities()) { context.Schools.Attach(school); context.Entry(school).State = EntityState.Modified; context.SaveChanges(); } return true; } catch (Exception ex) { return false; } }
private void LoadScheduler() { using (var context = new UzoneEntities()) { if (Session["currentSchoolID"] != null) { var currentSchool = (long)Session["currentSchoolID"]; List<Scheduler> _schedulers; _schedulers = context.Set<Scheduler>().Where(s => s.SchoolID == currentSchool).ToList(); RadScheduler1.DataSource = _schedulers; } } }
private Boolean emailExist(string emailAddress) { using (var context = new UzoneEntities()) { var foundEmail = (from fe in context.RegisteredUsers where fe.Email == emailAddress select fe); if (foundEmail.Any()) return true; else return false; } }
private void resetAndSend(string emailAddress) { using (var context = new UzoneEntities()) { RegisteredUser foundUser = (from fu in context.RegisteredUsers where fu.Email == emailAddress select fu).FirstOrDefault(); if (foundUser != null) { foundUser.Password = CreateRandomPassword(); context.RegisteredUsers.Attach(foundUser); context.Entry(foundUser).State = EntityState.Modified; context.SaveChanges(); sendMail(foundUser.Email, foundUser.Name, "Here is your new password: "******". Once you login, use the manage profile module to reset your password."); } } }
private void sendUsername(string emailAddress) { using (var context = new UzoneEntities()) { RegisteredUser foundUsername = (from fu in context.RegisteredUsers where fu.Email == emailAddress select fu).FirstOrDefault(); if (foundUsername != null) sendMail(foundUsername.Email, foundUsername.Name, "Here is your username: " + foundUsername.UserName); } }