protected void registerButton_Click(object sender, EventArgs e) { int schoolId; if (!int.TryParse(EmailDropdown.SelectedValue, out schoolId)) { ShowError("Please select a school."); return; } College school = College.Get(schoolId); if (school == null) { ShowError("Please select a school."); return; } string email = EmailTextbox.Text.ToLower() + "@" + school.ShortName.ToLower() + ".edu"; string primaryName = PrimaryNameTextbox.Text; string secondaryName = SecondaryNameTextbox.Text; string password = PasswordTextbox.Text; string confirmation = ConfirmPasswordTextbox.Text; bool organization = TypeRadioButtonList.SelectedIndex == 3; if (!IsDataValid(email, primaryName, secondaryName, password, confirmation, organization)) { return; } int verification = GenerateVerificationCode(); Debug.WriteLine(verification); int userId = Database.RegisterUser(school, email, primaryName, secondaryName, password, organization, verification); if (userId < 0) { ShowError("An error has occurred. Please try again."); return; } if (!Zoho.SendActivationEmail(email, primaryName, userId, verification)) { ShowError("An error has occurred. Please try again."); return; } school.Users++; Session["Email"] = email; Response.Redirect("~/Thanks.aspx"); }
private College GetSchool() { string school = GetCookieData("School"); try { return(College.Get(int.Parse(school))); } catch { return(null); } }
private string GetSchool() { string school = GetCookieData("School"); if (!string.IsNullOrEmpty(school)) { College schoolObject = College.Get(int.Parse(school)); if (schoolObject != null) { return(" " + schoolObject.ShortName); } } return(string.Empty); }
protected void Page_Load(object sender, EventArgs e) { string id = Page.RouteData.Values["id"] as string; if (string.IsNullOrEmpty(id)) { Response.Redirect("~/"); return; } int idInt; if (!int.TryParse(id, out idInt)) { Response.Redirect("~/"); return; } Advertisement ad = Database.GetAd(idInt); if (ad == null) { Response.Redirect("~/"); return; } ListingId.Value = id; College school = College.Get(ad.School); if (school == null) { Response.Redirect("~/"); return; } SetBannerAndTitle(school.ShortName, id); SetPageMenu(school.Name, school.ShortName); SetCustomHeaderColor(school); if (ad.Deleted) { AdTitle.Attributes["class"] = "deleted"; AdTitle.InnerText = "This listing has been deleted."; AdBody.Visible = false; return; } if (ad.IsExpired()) { AdTitle.Attributes["class"] = "expiration"; AdTitle.InnerText = "This listing has expired."; AdBody.Visible = false; return; } User owner = Database.GetUser(ad.User); if (owner == null) { Response.Redirect("~/"); return; } SetPageContent(ad, owner); SetListingImages(ad); SetReportReasons(); AddSocialMedia(id); Database.AddListingView(ad.Id); }
public static void SetSchoolStats() { MySqlDataReader reader = null; MySqlCommand command = null; try { connection.Open(); string query = "SELECT school, COUNT(*) as info FROM users GROUP BY school ASC UNION SELECT school, COUNT(*) as listings FROM listings GROUP BY school ORDER BY school ASC"; command = new MySqlCommand(query, connection); reader = command.ExecuteReader(); command.Dispose(); if (reader.HasRows) { while (reader.Read()) { int id = reader.GetInt16("school"); int users = reader.GetInt16("info"); reader.Read(); int listings = reader.GetInt16("info"); College college = College.Get(id); if (college == null) { continue; } college.Users = users; college.Listings = listings; } reader.Close(); reader.Dispose(); command.Dispose(); connection.Close(); } } catch (Exception exception) { Utility.Log(exception); } finally { if (reader != null) { reader.Close(); reader.Dispose(); } if (command != null) { command.Dispose(); } if (connection != null && connection.State == ConnectionState.Open) { connection.Close(); } } }
public static User GetUser(int userid, string userEmail) { MySqlDataReader reader = null; MySqlCommand command = null; string column = userid > 0 ? "id" : "email"; string value = userid > 0 ? userid.ToString() : userEmail; try { connection.Open(); string query = "SELECT id, email, password, school, primaryname, secondaryname, phone, credit, organization, status FROM users WHERE " + column + " = @Value"; command = new MySqlCommand(query, connection); command.Parameters.AddWithValue("@Value", value); reader = command.ExecuteReader(); command.Dispose(); if (reader.HasRows) { while (reader.Read()) { int id = reader.GetInt16("id"); string email = reader.GetString("email"); string password = reader.GetString("password"); int school = reader.GetInt16("school"); string primaryname = GetStringData(reader, "primaryname"); string secondaryname = GetStringData(reader, "secondaryname"); string phone = GetStringData(reader, "phone"); int credit = reader.GetInt32("credit"); bool organization = reader.GetInt16("organization") == 1; int status = reader.GetInt32("status"); User user = new User { Id = id, Email = email, Password = password, School = College.Get(school), PrimaryName = primaryname, SecondaryName = secondaryname, PhoneNumber = phone, Credit = credit, Organization = organization, Status = status }; reader.Close(); reader.Dispose(); command.Dispose(); connection.Close(); return(user); } } } catch (Exception exception) { Utility.Log(exception); } finally { if (reader != null) { reader.Close(); reader.Dispose(); } if (command != null) { command.Dispose(); } if (connection != null && connection.State == ConnectionState.Open) { connection.Close(); } } return(null); }
protected void Page_Load(object sender, EventArgs e) { string schoolName = Page.RouteData.Values["name"] as string; string filterName = Page.RouteData.Values["filter"] as string; string info1 = Page.RouteData.Values["info1"] as string; string info2 = Page.RouteData.Values["info2"] as string; if (string.IsNullOrEmpty(schoolName)) { Response.Redirect("~/Schools.aspx"); return; } College school = College.Get(schoolName); if (school == null) { Response.Redirect("~/Schools.aspx"); return; } Filter filter = Filter.Get(filterName); if (filter == null) { filter = Filter.GetFilters()[0]; } Subcategory subcategory = null; int page; int.TryParse(info1, out page); if (filter.HasSubCategories() && page < 1) { subcategory = filter.Category.GetSubcategory(info1); int.TryParse(info2, out page); } if (page < 1) { page = 1; } List <Advertisement> advertisements = Database.GetAds(school.Id, filter.GetQuery(subcategory), page, Order.Boosted); AddAds(advertisements); string subUrl = subcategory != null ? subcategory.Name + "/" : ""; AddNavigation(advertisements, "~/School/" + school.ShortName + "/" + filter.Name + "/" + subUrl, page); Page.Title = "Zhigly - " + filter.Name + " listings at " + school.ShortName; Banner.ImageUrl = "~/Images/SchoolBanner/" + school.ShortName + ".png"; LeftHeader.InnerText = school.Name; ListingsSection.InnerText = (subcategory != null? subcategory.Name : filter.Name) + " listings at " + school.Name; PageNumber.InnerText = "Page " + page; AddSubcategories(filter, subcategory, school); AddFilters(schoolName, filter); SetCustomHeaderColor(school); }