public ActionResult Post() { var model = Session["CreatePostModel"] as CreatePostModel; grabFromDB grab = new grabFromDB(); UserInfo temp = grab.getUserInfo(Globals.getCurrentUserEmail()); //string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); Post post = new Post(); post.code = model.Code; post.condition = model.Condition; post.coursename = model.CourseName; post.date = DateTime.Now.ToString(); post.department = model.Department; post.description = model.Description; post.edition = model.Edition; post.email = Globals.getCurrentUserEmail(); post.Phone = temp.phone; post.price = model.Price; post.Title = model.Title; post.Uni = temp.university; post.author = model.Author; ViewBag.Success = grab.insertPost(post); return(View("Success")); }
public ActionResult RemoveUni(UniModel m) { if (m.UNI_NAME == null) { ViewBag.EmptyFields = "Must not leave any University entry fields blank. Try again."; return(View("DeleteUni", m)); } grabFromDB DB = new grabFromDB(); if (DB.getUniversities().Count == 1) { ViewBag.InvalidUni = "Cannot delete the last university in the database. Try Again."; return(View("DeleteUni", m)); } if (DB.getUniversitiesByName(m.UNI_NAME).Count != 1) { ViewBag.InvalidUni = "This university does not exist in the database. Try Again."; return(View("DeleteUni", m)); } else { DB.removeUniversityByName(m.UNI_NAME); ViewBag.ReturnValue = "University successfully removed."; return(View("AdminPage")); } }
public ActionResult RemoveAdmin(AdminModel m) { if (m.UserEmail == null) { ViewBag.EmptyFielsAdnminEntry = "Must not leave any Admin entry fields blank. Try again."; return(View("DeleteAdmin", m)); } if (m.UserEmail == AbstractDatabase.AdminEmail) { ViewBag.InvalidEmail = "Cannot remove that admin. Try again."; return(View("DeleteAdmin", m)); } if (m.UserEmail.Length > 100) { ViewBag.InvalidEmail = "Email too long. Try again."; return(View("DeleteAdmin", m)); } grabFromDB DB = new grabFromDB(); //check if valid user if (DB.getAdminByEmail(m.UserEmail).Count == 0) { ViewBag.InvalidEmail = "This email is not associated with a current admin. Try again."; return(View("DeleteAdmin", m)); } else { DB.removeAdminByEmail(m.UserEmail); ViewBag.ReturnValue = "Admin successfully removed."; return(View("AdminPage")); } }
public ActionResult PerformSearch(AdminSearchUserModel m) { if (m.Email == null) { ViewBag.InvalidEmail = "Please do not leave blank. Try Again."; return(View("SearchUsers", m)); } if (m.Email.Length > 100) { ViewBag.InvalidEmail = "Email too long. Try Again."; } grabFromDB DB = new grabFromDB(); if (DB.getUserListByEmail(m.Email).Count != 1) { ViewBag.InvalidEmail = "That user does not exist. Try Again."; return(View("SearchUsers", m)); } else { User user = new User(); user = DB.getUserListByEmail(m.Email)[0]; ViewBag.User = user; Globals.setUserToModify(user); AdminUserResultModel model = new AdminUserResultModel(); var universities = GetAllUniversities(); model.Universities = GetSelectListItems(universities); return(View("UserEdit", model)); } }
public ActionResult MyPosts(string id) { grabFromDB grab = new grabFromDB(); List <Result> results = grab.getUserPosts(Globals.getCurrentUserEmail()); ViewBag.PostList = results; return(View("MyPosts")); }
public ActionResult Save(string id) { grabFromDB grab = new grabFromDB(); string phone = grab.getUserPhone(Globals.getCurrentUserEmail()); grab.saveFavourite(phone, Globals.getCurrentUserEmail(), id); return(RedirectToAction("Favourites")); }
public ActionResult Favourites() { grabFromDB grab = new grabFromDB(); List <Result> results = grab.getFavourites(Globals.getCurrentUserEmail()); ViewBag.FavouriteList = results; return(View("Favourites")); }
/// <summary> /// Method to delete a specific post /// </summary> /// <param name="PM"></param> /// <returns></returns> public ActionResult DeletePost(PostModel PM) { grabFromDB DB = new grabFromDB(); if (PM.ID != null) { DB.deletePost(PM.ID); } return(MyPosts("")); }
public ActionResult Results() { var model = Session["UniversityModel"] as UniversitiesModel; grabFromDB grabFromDB = new grabFromDB(); List <Result> results = grabFromDB.getSearchTitles(model.Title, model.Department, model.Code, model.University); ViewBag.Textbooklist = results; return(View("Results")); }
public ActionResult UniEntry(UniModel m) { //check for blank entries if (m.UNI_NAME == null || m.City == null || m.Prov_State == null || m.Country == null) { ViewBag.EmptyFields = "Must not leave any University entry fields blank. Try again."; return(View("AddUni", m)); } if (m.UNI_NAME.Length > 100) { ViewBag.InvalidUni = "University name too long. Try again."; return(View("AddUni", m)); } if (m.City.Length > 100) { ViewBag.InvalidCity = "City name too long. Try again."; return(View("AddUni", m)); } //check for two letter province if (m.Prov_State.Length != 2) { ViewBag.IncorectProv = "Province must be two letters. AB, BC, ect. Try Again."; return(View("AddUni", m)); } if (m.Country.Length > 100) { ViewBag.IncorrectCountry = "Country name too long."; return(View("AddUni", m)); } grabFromDB DB = new grabFromDB(); if (DB.getUniversitiesByName(m.UNI_NAME).Count != 0) { ViewBag.InvalidUni = "This university has already been entered. Try again."; return(View("AddUni", m)); } else { DB.insertUniversity(m.UNI_NAME, m.City, m.Prov_State, m.Country); ViewBag.ReturnValue = "University successfully added."; return(View("AdminPage")); } }
public ActionResult Textbook(string id) { grabFromDB grab = new grabFromDB(); Post post = grab.getPost(id); ViewBag.Post = post; Globals.setCurrentPostEmail(post.email); Globals.setCurrentPostId(post.ID); List <ReviewResults> results = grab.getReviewByEmail(post.email); ViewBag.ReviewList = results; return(View("Textbook")); }
private IEnumerable <string> GetAllUniversities() { //This could be a call to University in Database grabFromDB grabFromDB = new grabFromDB(); List <UniData> uni = grabFromDB.getUniversities(); List <string> output = new List <string>(); string temp; grabFromDB.close(); foreach (UniData data in uni) { temp = data.name; output.Add(temp); } return(output); }
public ActionResult AdminEntry(AdminModel m) { //check for blank entries if (m.UserEmail == null || m.Role == null) { ViewBag.EmptyFielsAdnminEntry = "Must not leave any Admin entry fields blank. Try again."; return(View("AddAdmin", m)); } if (m.UserEmail.Length > 100) { ViewBag.InvalidEmail = "Email too long. Try again."; return(View("AddAdmin", m)); } if (m.Role.Length > 200) { ViewBag.InvalidRole = "Role too long. Try again."; return(View("AddAdmin", m)); } grabFromDB DB = new grabFromDB(); if (DB.getAdminByEmail(m.UserEmail).Count != 0) { ViewBag.InvalidEmail = "The user associated with this account is already an admin. Try again."; return(View("AddAdmin", m)); } //check if valid user if (DB.getUserListByEmail(m.UserEmail).Count == 0) { ViewBag.InvalidEmail = "This email is not associated with a current account. Try again."; return(View("AddAdmin", m)); } else { DB.insertAdmin(m.UserEmail, m.Role); ViewBag.ReturnValue = "Admin successfully added."; return(View("AdminPage")); } }
public ActionResult LogIn(LoginModel m) { if (m.Email == null || m.Password == null) { ViewBag.LogInError = "Username or password incorrect. Try again."; return(View("Index", m)); } grabFromDB DB = new grabFromDB(); List <User> list = DB.getUsers(m.Email, m.Password); if (list.Count == 0) { ViewBag.LogInError = "Username or password incorrect. Try again."; return(View("Index", m)); } else { Globals.setCurrentUser(m.Email); return(RedirectToAction("FrontPage", "Home")); } }
public ActionResult AddReview(ReviewModel m) { string email = Globals.getCurrentPostEmail(); grabFromDB DB = new grabFromDB(); List <User> user = DB.getUserListByEmail(email); if (user.Count != 1) { //there was an error, must handle } else { m.Email = user[0].email; m.Phone_Num = user[0].phone; } //check for empty fields if (m.Email == null || m.Phone_Num == null || m.Reviewer_Email == null || m.Description == null || m.Rating == null) { ViewBag.EmptyFields = "Please fill out all feilds."; return(View("ReviewUser", m)); } //Check for invalid email try { MailAddress mail = new MailAddress(m.Reviewer_Email); } catch (FormatException) { ViewBag.InvalidEmail = "This is not a valid email address. Try again."; return(View("ReviewUser", m)); } //check description length if (m.Description.Length > 400) { ViewBag.DescriptionLengthError = "Review too long. Try again."; return(View("ReviewUser", m)); } //check email length if (m.Reviewer_Email.Length > 100) { ViewBag.InvalidEmail = "Email too long. Try again."; return(View("ReviewUser", m)); } int rating; if (m.Rating == Enum.GetName(typeof(ratings), 0)) { rating = 1; } else if (m.Rating == Enum.GetName(typeof(ratings), 1)) { rating = 2; } else if (m.Rating == Enum.GetName(typeof(ratings), 2)) { rating = 3; } else if (m.Rating == Enum.GetName(typeof(ratings), 3)) { rating = 4; } else if (m.Rating == Enum.GetName(typeof(ratings), 4)) { rating = 5; } else { //error, should never get here though rating = 5; } DB.insertReview(m.Phone_Num, m.Email, m.Reviewer_Email, m.Description, rating); int id = Globals.getCurrentPostId(); return(RedirectToAction("Textbook/" + id, "Post")); }
public ActionResult ModifyUser(AdminUserResultModel m) { User toModify = Globals.getUserToModify(); grabFromDB DB = new grabFromDB(); List <string> modifiedReturn = new List <string>(); if (m.Email != null && toModify.email != m.Email) { if (m.Email.Length > 100) { ViewBag.InvalidEmail = "Email too long. Try again."; ViewBag.User = toModify; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("UserEdit", m)); } if (DB.getUserListByEmail(m.Email).Count == 1) { ViewBag.InvalidEmail = "This email is already associated with an account. Try again."; ViewBag.User = toModify; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("UserEdit", m)); } //Check for invalid email try { MailAddress mail = new MailAddress(m.Email); } catch (FormatException) { ViewBag.InvalidEmail = "This is not a valid email address. Try again."; ViewBag.User = toModify; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("UserEdit", m)); } DB.modifyUserEmail(m.Email, toModify.email); toModify.email = m.Email; modifiedReturn.Add("Email successfully changed."); } if (m.Password != null && toModify.pw != m.Password) { if (m.Password != m.confirmPassword) { ViewBag.InvalidPassword = "******"; ViewBag.User = toModify; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("UserEdit", m)); } if (m.Password.Length > 100 || m.confirmPassword.Length > 100) { ViewBag.InvalidPassword = "******"; ViewBag.User = toModify; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("UserEdit", m)); } DB.modifyUserPassword(m.Password, toModify.pw, toModify.email); modifiedReturn.Add("Password successfully changed"); } if (m.Fname != null && toModify.fname != m.Fname) { if (m.Fname.Length > 100) { ViewBag.InvalidFname = "First name too long. Try again."; ViewBag.User = toModify; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("UserEdit", m)); } DB.modifyUserFname(m.Fname, toModify.fname, toModify.email); modifiedReturn.Add("First name successfully changed"); } if (m.Lname != null && toModify.lname != m.Lname) { if (m.Lname.Length > 100) { ViewBag.InvalidLname = "Last name too long. Try again."; ViewBag.User = toModify; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("UserEdit", m)); } DB.modifyUserLname(m.Lname, toModify.lname, toModify.email); modifiedReturn.Add("Last name successfully changed."); } if (m.Phone_Num != null && toModify.phone != m.Phone_Num) { if (m.Phone_Num.Length > 14) { ViewBag.InvalidPhone = "Phone number too long. Try again."; ViewBag.User = toModify; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("UserEdit", m)); } Regex rg = new Regex(@"^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$"); if (!rg.IsMatch(m.Phone_Num)) { ViewBag.InvalidPhone = "This is not a valid phone number. Try again."; ViewBag.User = toModify; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("UserEdit", m)); } if (DB.getUserListByPhone(m.Phone_Num).Count == 1) { ViewBag.InvalidPhone = "Phone number already associated with an account. Try again."; ViewBag.User = toModify; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("UserEdit", m)); } DB.modifyUserPhone(m.Phone_Num, toModify.phone, toModify.email); modifiedReturn.Add("Phone number successfully changed."); } if (m.University != null && m.University != toModify.Uni) { DB.modifyUserUniversity(m.University, toModify.Uni, toModify.email); modifiedReturn.Add("University successfully changed."); } ViewBag.ModifiedReturn = modifiedReturn; return(View("AdminPage")); }
public ActionResult CreationSubmittion(AccountCreation m) { //check for blank entries if (m.Email == null || m.Password == null || m.confirmPassword == null || m.Fname == null || m.Lname == null || m.Phone_Num == null) { ViewBag.EmptyFields = "Must not leave any blank. Try again."; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("AccountCreation", m)); } //Check lengths if (m.Phone_Num.Length > 14) { ViewBag.InvalidPhone = "Phone number too long. Try again."; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("AccountCreation", m)); } if (m.Email.Length > 100) { ViewBag.InvalidEmail = "Email too long. Try again."; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("AccountCreation", m)); } if (m.Fname.Length > 100) { ViewBag.InvalidFname = "First name too long. Try again."; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("AccountCreation", m)); } if (m.Lname.Length > 100) { ViewBag.InvalidLname = "Last name too long. Try again."; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("AccountCreation", m)); } if (m.Password.Length > 100) { ViewBag.InvalidPassword = "******"; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("AccountCreation", m)); } //check for matching passwords if (!m.Password.Equals(m.confirmPassword)) { ViewBag.InvalidPassword = "******"; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("AccountCreation", m)); } //Check for invalid email try { MailAddress mail = new MailAddress(m.Email); } catch (FormatException) { ViewBag.InvalidEmail = "This is not a valid email address. Try again."; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("AccountCreation", m)); } //Check for invalid phone_num - TODO need to fix to make areacode manditory Regex rg = new Regex(@"^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$"); if (!rg.IsMatch(m.Phone_Num)) { ViewBag.InvalidPhone = "This is not a valid phone number. Try again."; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("AccountCreation", m)); } grabFromDB DB = new grabFromDB(); //must check to see if user already exists if (DB.getUserListByEmail(m.Email).Count != 0) { ViewBag.InvalidEmail = "Email already used. Try a different one."; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("AccountCreation", m)); } if (DB.getUserListByPhone(m.Phone_Num).Count != 0) { ViewBag.InvalidPhone = "This phone number is already linked to an account. Please enter different one."; var universities = GetAllUniversities(); m.Universities = GetSelectListItems(universities); return(View("AccountCreation", m)); } DB.insertUser(m.Phone_Num, m.Email, m.University, m.Fname, m.Lname, m.Password); ViewBag.SuccessfullyCreated = "Your account was successfully created. Thanks for joining! Please sign in to continue."; LoginModel model = new LoginModel(); return(View("LogIn", model)); }