public void createUser(user newUser) { SqlConnection conn = null; SqlCommand cmd = null; SqlDataReader reader = null; conn = new SqlConnection(ConfigurationManager.ConnectionStrings["vetoTours"].ToString()); conn.Open(); string query = "INSERT INTO users VALUES('" + newUser.getUserID() + "', '" + newUser.getPassword() + "', '" + newUser.getName() + "', '" + newUser.getEmail() + "', '" + newUser.getPhoneNumber() + "', '" + newUser.getPersonalDescription() + "', '" + newUser.getStatus() + "')"; cmd = new SqlCommand(query, conn); reader = cmd.ExecuteReader(); reader.Close(); conn.Close(); }
protected void giveRatingTourGuideController(object sender, EventArgs e) { ratingErrorHandler ratingHandler = new ratingErrorHandler(); if (rateTourGuideID.Text == "") { ratingHandler.emptyIDField(); } // Fetch tourGuide object that user wants to rate user tourGuide = fetchUserObject(rateTourGuideID.Text); if (rateTourGuideID.Text != "") { if (tourGuide == null) { ratingHandler.noSuchUser(); } } if (ratingHandler.error == "") { // Create new rating object rating newRating = new rating(tourGuide.getUserID(), currUser.getUserID(), int.Parse(ddTourGuideStars.SelectedValue), "tourguide"); // Execute write rating to database newRating.createRating(); Session["success"] = "giveRating"; general_dialog.Visible = false; Response.Redirect("main.aspx"); } else { general_dialog.InnerHtml = ratingHandler.error; general_dialog.Visible = true; } }
public void suspendUser(user targetUser) { SqlConnection conn = null; SqlCommand cmd = null; SqlDataReader reader = null; conn = new SqlConnection(ConfigurationManager.ConnectionStrings["vetoTours"].ToString()); conn.Open(); string query = "UPDATE users SET password= '******', name='" + targetUser.getName() + "', email ='" + targetUser.getEmail() + "', phoneNumber=" + targetUser.getPhoneNumber() + ", description ='" + targetUser.getPersonalDescription() + "', status=" + targetUser.getStatus() + " WHERE userID='" + targetUser.getUserID() + "';"; cmd = new SqlCommand(query, conn); reader = cmd.ExecuteReader(); reader.Close(); query = "UPDATE tours SET status= 'suspended' WHERE userID='" + targetUser.getUserID() + "';"; cmd = new SqlCommand(query, conn); reader = cmd.ExecuteReader(); conn.Close(); }
// Create tour protected void tourCreationController(object sender, EventArgs e) { TourErrorHandler tourHandler = new TourErrorHandler(); string tempStart = createStartDate.Text; string tempEnd = createEndDate.Text; double test; bool tryDouble = double.TryParse(createPrice.Text, out test); if (createTourName.Text == "") { tourHandler.emptyTourName(); } if (createCapacity.Text == "") { tourHandler.emptyCapacity(); } if (!createCapacity.Text.All(char.IsDigit)) { tourHandler.invalidCapacity(); } if (createLocation.Text == "") { tourHandler.emptyLocation(); } if (createDescription.Text == "") { tourHandler.emptyDescription(); } if (createStartDate.Text == "") { tourHandler.emptyStartDate(); } else if (!System.Text.RegularExpressions.Regex.IsMatch(tempStart, "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}")) { tourHandler.invalidStartDate(); } if (createEndDate.Text == "") { tourHandler.emptyEndDate(); } else if (!System.Text.RegularExpressions.Regex.IsMatch(tempEnd, "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}")) { tourHandler.invalidEndDate(); } if (createPrice.Text == "") { tourHandler.emptyPrice(); } if (tryDouble == false) { tourHandler.invalidPrice(); } if (tourHandler.error == "") { DateTime startDate = DateTime.ParseExact(tempStart, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); DateTime endDate = DateTime.ParseExact(tempEnd, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); if (endDate <= startDate) { tourHandler.endBeforeStart(); } if (tourHandler.error == "") { tour newTour = new tour(currUser.getUserID(), createTourName.Text, int.Parse(createCapacity.Text), createLocation.Text, createDescription.Text, startDate, endDate, double.Parse(createPrice.Text), ddCreateStatus.SelectedValue); newTour.createTour(); general_dialog.Visible = false; Session["success"] = "tourCreated"; Response.Redirect("main.aspx"); } else { general_dialog.InnerHtml = tourHandler.error; general_dialog.Visible = true; } } else { general_dialog.InnerHtml = tourHandler.error; general_dialog.Visible = true; } }