public bool AddStandingTeeTimeRequest(StandingTeeTimeRequest selectedStandingTeeTimeRequest) { using var connection = new SqlConnection(ConnectionString); using var command = new SqlCommand("EditStandingTeeTimeRequest", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@StartDate", SqlDbType.Date).Value = selectedStandingTeeTimeRequest.StartDate.Date; command.Parameters.Add("@EndDate", SqlDbType.Date).Value = selectedStandingTeeTimeRequest.EndDate.Date; command.Parameters.Add("@Time", SqlDbType.Time).Value = selectedStandingTeeTimeRequest.Time.TimeOfDay; command.Parameters.Add("@DayOfWeek", SqlDbType.VarChar).Value = selectedStandingTeeTimeRequest.DayOfWeek; command.Parameters.Add("@bookerId", SqlDbType.NVarChar).Value = selectedStandingTeeTimeRequest.BookerId; command.Parameters.Add("@shareholder1", SqlDbType.VarChar).Value = selectedStandingTeeTimeRequest.Shareholder1.FullName == " " ? null : selectedStandingTeeTimeRequest.Shareholder1.FullName; command.Parameters.Add("@shareholder2", SqlDbType.VarChar).Value = selectedStandingTeeTimeRequest.Shareholder2.FullName == " " ? null : selectedStandingTeeTimeRequest.Shareholder2.FullName; command.Parameters.Add("@shareholder3", SqlDbType.VarChar).Value = selectedStandingTeeTimeRequest.Shareholder3.FullName == " " ? null : selectedStandingTeeTimeRequest.Shareholder3.FullName; command.Parameters.Add("@shareholder4", SqlDbType.VarChar).Value = selectedStandingTeeTimeRequest.Shareholder4.FullName == " " ? null : selectedStandingTeeTimeRequest.Shareholder4.FullName; //Open the connection and execute the reader connection.Open(); var success = command.ExecuteNonQuery(); connection.Close(); return(success != 0); }
public ActionResult OnPost(string submit) { var authenticatedUser = ClubBaistUsers.GetUserFromUserName(User.Identity.Name); var requestedDayOfWeek = Request.Query["day"]; var requestedTime = DateTime.Parse(Request.Query["time"]); var requestedStartDate = InputtedStartDate; var requestedEndDate = InputtedEndDate; if (!ModelState.IsValid) { return(Page()); } var result = false; _selectedStandingTeeTimeRequest = _requestDirector.FindStandingTeeTimeRequest(requestedDayOfWeek, requestedStartDate, requestedEndDate, requestedTime); _selectedStandingTeeTimeRequest.Shareholder1.FullName = InputtedShareholder1; _selectedStandingTeeTimeRequest.Shareholder2.FullName = InputtedShareholder2; _selectedStandingTeeTimeRequest.Shareholder3.FullName = InputtedShareholder3; _selectedStandingTeeTimeRequest.Shareholder4.FullName = InputtedShareholder4; if (IsNullOrEmpty(_selectedStandingTeeTimeRequest.BookerId) || _selectedStandingTeeTimeRequest.BookerId == " " || _selectedStandingTeeTimeRequest.BookerId == "") { _selectedStandingTeeTimeRequest.BookerId = authenticatedUser.Id; } if (submit == "cancelStandingTeeTimeRequest") { _selectedStandingTeeTimeRequest.BookerId = " "; } result = submit switch { "submitStandingTeeTimeRequest" => _requestDirector.SubmitStandingTeeTimeRequest(_selectedStandingTeeTimeRequest), "cancelStandingTeeTimeRequest" => _requestDirector.CancelStandingTeeTimeRequest(_selectedStandingTeeTimeRequest), _ => result }; if (!result) { return(Page()); } Alert = $"Edited Standing Time for {requestedDayOfWeek} at {requestedTime:hh:mm tt}"; return(RedirectToPage("SubmitStandingTeeTimeRequest")); } }
public StandingTeeTimeRequest GetStandingTeeTimeRequest(string dayOfWeek, DateTime startDate, DateTime endDate, DateTime time) { { var golferManager = new ClubBaistUsers(); var requestedStandingTeeTimeRequest = new StandingTeeTimeRequest(); using var connection = new SqlConnection(ConnectionString); using var command = new SqlCommand("FindStandingTeeTimeRequest", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@dayOfWeek", SqlDbType.VarChar).Value = dayOfWeek; command.Parameters.Add("@startDate", SqlDbType.VarChar).Value = startDate; command.Parameters.Add("@endDate", SqlDbType.VarChar).Value = endDate; command.Parameters.Add("@time", SqlDbType.VarChar).Value = time; //Open the connection and execute the reader connection.Open(); var reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { // Mapping the program Object to Database requestedStandingTeeTimeRequest = new StandingTeeTimeRequest { Time = new DateTime(((TimeSpan)reader[0]).Ticks), DayOfWeek = (string)reader[1], Shareholder1 = !DBNull.Value.Equals(reader[2]) ? golferManager.GetUserFromId((string)reader[2]) : new Shareholder(), Shareholder2 = !DBNull.Value.Equals(reader[3]) ? golferManager.GetUserFromId((string)reader[3]) : new Shareholder(), Shareholder3 = !DBNull.Value.Equals(reader[4]) ? golferManager.GetUserFromId((string)reader[4]) : new Shareholder(), Shareholder4 = !DBNull.Value.Equals(reader[5]) ? golferManager.GetUserFromId((string)reader[5]) : new Shareholder() }; } } reader.Close(); return(requestedStandingTeeTimeRequest); } }
public List <StandingTeeTimeRequest> GetStandingTeeTimeRequests(string dayOfWeek) { { var golferManager = new ClubBaistUsers(); var requestedStandingTeeTimeRequests = new List <StandingTeeTimeRequest>(); using var connection = new SqlConnection(ConnectionString); using var command = new SqlCommand("GetAvailableStandingTeeTimeRequestsByDay", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@DayOfWeek", SqlDbType.VarChar).Value = dayOfWeek; //Open the connection and execute the reader connection.Open(); var reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { // Mapping the program Object to Database var standingTeeTimeRequestDbInstance = new StandingTeeTimeRequest { Time = new DateTime(((TimeSpan)reader[0]).Ticks), DayOfWeek = (string)reader[1], Shareholder1 = !DBNull.Value.Equals(reader[2]) ? golferManager.GetUserFromId((string)reader[2]) : new Shareholder(), Shareholder2 = !DBNull.Value.Equals(reader[3]) ? golferManager.GetUserFromId((string)reader[3]) : new Shareholder(), Shareholder3 = !DBNull.Value.Equals(reader[4]) ? golferManager.GetUserFromId((string)reader[4]) : new Shareholder(), Shareholder4 = !DBNull.Value.Equals(reader[5]) ? golferManager.GetUserFromId((string)reader[5]) : new Shareholder() }; requestedStandingTeeTimeRequests.Add(standingTeeTimeRequestDbInstance); } } reader.Close(); return(requestedStandingTeeTimeRequests); } }
public ActionResult OnPostCancel() { if (ModelState.IsValid) { Day = Request.Query["day"].ToString(); TimeSlot = DateTime.Parse(Request.Query["time"]); chosenstandingRequest = RequestDirector.FindReservedStandingTeeTime(Day, TimeSlot, RequestedStartDate, RequestedEndDate); Confirmation = RequestDirector.CancelStandingTeeTimeRequest(chosenstandingRequest); if (Confirmation) { Alert = $"Standing Tee Time Cancelled successfully!"; return(RedirectToPage("SubmitStandingTeeTime")); } } return(Page()); }
public void OnGet() { string dayOfWeek = Request.Query["day"]; var time = DateTime.Parse(Request.Query["time"]); StandingTeeTimeRequests = _requestDirector.FindStandingTeeTimeRequests(dayOfWeek); foreach (var standingTeeTimeRequest in StandingTeeTimeRequests.Where(standingTeeTimeRequest => standingTeeTimeRequest.DayOfWeek == dayOfWeek && standingTeeTimeRequest.Time.ToString("hh:mm tt") == time.ToString("hh:mm tt"))) { InputtedShareholder1 = standingTeeTimeRequest.Shareholder1.FullName; InputtedShareholder2 = standingTeeTimeRequest.Shareholder2.FullName; InputtedShareholder3 = standingTeeTimeRequest.Shareholder3.FullName; InputtedShareholder4 = standingTeeTimeRequest.Shareholder4.FullName; InputtedStartDate = standingTeeTimeRequest.StartDate; InputtedEndDate = standingTeeTimeRequest.EndDate; _selectedStandingTeeTimeRequest = standingTeeTimeRequest; } }
public bool CancelStandingTeeTimeRequest(StandingTeeTimeRequest selectedStandingTeeTimeRequest) { return(_standingTeeTimeRequestsManager.RemoveStandingTeeTimeRequest(selectedStandingTeeTimeRequest)); }
public bool SubmitStandingTeeTimeRequest(StandingTeeTimeRequest selectedStandingTeeTimeRequest) { return(_standingTeeTimeRequestsManager.AddStandingTeeTimeRequest(selectedStandingTeeTimeRequest)); }
public StandingTeeTimeRequest GetReservedStandingTeeTime(string DayOfWeek, DateTime requestedTime, DateTime requestedStartDate, DateTime requestedEndDate) { StandingTeeTimeRequest standingteetimerequest = new StandingTeeTimeRequest(); SqlConnection ClubBaistConnection = new SqlConnection(); ClubBaistConnection.ConnectionString = @"Data Source= (LocalDB)\MSSQLLocalDB; Initial Catalog = aspnet-ClubBaistGolfManagement-53bc9b9d-9d6a-45d4-8429-2a2761773502; Integrated Security = True; MultipleActiveResultSets=True"; SqlCommand thecommand = new SqlCommand(); thecommand.CommandType = CommandType.StoredProcedure; thecommand.Connection = ClubBaistConnection; thecommand.CommandText = "GetReservedStandingTeeTime"; SqlParameter day = new SqlParameter(); day.ParameterName = "@dayofweek"; day.SqlDbType = SqlDbType.VarChar; day.Value = DayOfWeek; day.Direction = ParameterDirection.Input; thecommand.Parameters.Add(day); SqlParameter time = new SqlParameter(); time.ParameterName = "@time"; time.SqlDbType = SqlDbType.Time; time.Value = requestedTime; time.Direction = ParameterDirection.Input; thecommand.Parameters.Add(time); SqlParameter startDate = new SqlParameter(); startDate.ParameterName = "@startDate"; startDate.SqlDbType = SqlDbType.Date; startDate.Value = requestedStartDate; startDate.Direction = ParameterDirection.Input; thecommand.Parameters.Add(startDate); SqlParameter endDate = new SqlParameter(); endDate.ParameterName = "@endDate"; endDate.SqlDbType = SqlDbType.Date; endDate.Value = requestedEndDate; endDate.Direction = ParameterDirection.Input; thecommand.Parameters.Add(endDate); ClubBaistConnection.Open(); SqlDataReader theDataReader; theDataReader = thecommand.ExecuteReader(); CBSUsers UserManager = new CBSUsers(); if (theDataReader.HasRows) { while (theDataReader.Read()) { standingteetimerequest.RequestedTime = DateTime.Parse(theDataReader["RequestedTeeTime"].ToString()); standingteetimerequest.DayofWeek = theDataReader["DayofWeek"].ToString(); standingteetimerequest.RequestedEndDate = DateTime.Parse(theDataReader["RequestedEndDate"].ToString()); standingteetimerequest.Shareholder1 = !string.IsNullOrEmpty(theDataReader["Shareholder1Number"].ToString()) ? UserManager.GetUser((string)(theDataReader["Shareholder1Number"])) : new Shareholder(); standingteetimerequest.Shareholder2 = !string.IsNullOrEmpty(theDataReader["Shareholder2Number"].ToString()) ? UserManager.GetUser((string)(theDataReader["Shareholder2Number"])) : new Shareholder(); standingteetimerequest.Shareholder3 = !string.IsNullOrEmpty(theDataReader["Shareholder3Number"].ToString()) ? UserManager.GetUser((string)(theDataReader["Shareholder3Number"])) : new Shareholder(); standingteetimerequest.Shareholder4 = !string.IsNullOrEmpty(theDataReader["Shareholder4Number"].ToString()) ? UserManager.GetUser((string)(theDataReader["Shareholder4Number"])) : new Shareholder(); } theDataReader.Close(); ClubBaistConnection.Close(); } return(standingteetimerequest); }
public bool RemoveStandingTeeTimeRequest(StandingTeeTimeRequest standingTeeTime) { bool confirmation; SqlConnection ClubBaistConnection = new SqlConnection(); ClubBaistConnection.ConnectionString = @"Data Source= (LocalDB)\MSSQLLocalDB; Initial Catalog = aspnet-ClubBaistGolfManagement-53bc9b9d-9d6a-45d4-8429-2a2761773502; Integrated Security = True; MultipleActiveResultSets=True"; SqlCommand thecommand = new SqlCommand(); thecommand.CommandType = CommandType.StoredProcedure; thecommand.Connection = ClubBaistConnection; thecommand.CommandText = "CancelStandingTeeTime"; //dayofweek SqlParameter day = new SqlParameter(); day.ParameterName = "@dayofweek"; day.SqlDbType = SqlDbType.VarChar; day.Value = standingTeeTime.DayofWeek; day.Direction = ParameterDirection.Input; thecommand.Parameters.Add(day); //RequestedTeeTime SqlParameter time = new SqlParameter(); time.ParameterName = "@reqTime"; time.SqlDbType = SqlDbType.VarChar; time.Value = standingTeeTime.RequestedTime; time.Direction = ParameterDirection.Input; thecommand.Parameters.Add(time); //RequestedStartDate SqlParameter sdate = new SqlParameter(); sdate.ParameterName = "@reqStartDate"; sdate.SqlDbType = SqlDbType.VarChar; sdate.Value = standingTeeTime.RequestedStartDate; sdate.Direction = ParameterDirection.Input; thecommand.Parameters.Add(sdate); //RequestedEndDate SqlParameter edate = new SqlParameter(); edate.ParameterName = "@reqEndDate"; edate.SqlDbType = SqlDbType.VarChar; edate.Value = standingTeeTime.RequestedEndDate; edate.Direction = ParameterDirection.Input; thecommand.Parameters.Add(edate); //Shareholder1Number SqlParameter s1n = new SqlParameter(); s1n.ParameterName = "@Shareholder1"; s1n.SqlDbType = SqlDbType.VarChar; s1n.Value = " "; s1n.Direction = ParameterDirection.Input; thecommand.Parameters.Add(s1n); //Shareholder2Number SqlParameter s2n = new SqlParameter(); s2n.ParameterName = "@Shareholder2"; s2n.SqlDbType = SqlDbType.VarChar; s2n.Value = " "; s2n.Direction = ParameterDirection.Input; thecommand.Parameters.Add(s2n); //Shareholder3Number SqlParameter s3n = new SqlParameter(); s3n.ParameterName = "@Shareholder3"; s3n.SqlDbType = SqlDbType.VarChar; s3n.Value = " "; s3n.Direction = ParameterDirection.Input; thecommand.Parameters.Add(s3n); //Shareholder4Number SqlParameter s4n = new SqlParameter(); s4n.ParameterName = "@Shareholder4"; s4n.SqlDbType = SqlDbType.VarChar; s4n.Value = " "; s4n.Direction = ParameterDirection.Input; thecommand.Parameters.Add(s4n); //Booker SqlParameter booker = new SqlParameter(); booker.ParameterName = "@booker"; booker.SqlDbType = SqlDbType.VarChar; booker.Value = " "; booker.Direction = ParameterDirection.Input; thecommand.Parameters.Add(booker); ClubBaistConnection.Open(); int rowsaffected = thecommand.ExecuteNonQuery(); if (rowsaffected >= 1) { confirmation = true; } else { confirmation = false; } ClubBaistConnection.Close(); return(confirmation); }