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);
            }
        }
Exemplo n.º 2
0
        public TeeTime GetTeeTime(DateTime selectedTime, DateTime selectedDate)
        {
            var requestedTeeTime = new TeeTime();

            using var connection = new SqlConnection(ConnectionString);
            using var command    = new SqlCommand("GetTeeTimeByDateAndTime", connection);
            command.CommandType  = CommandType.StoredProcedure;
            command.Parameters.Add("@Date", SqlDbType.VarChar).Value = selectedDate;
            command.Parameters.Add("@Time", SqlDbType.VarChar).Value = selectedTime;

            //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
                {
                    requestedTeeTime.Date    = (DateTime)reader[0];
                    requestedTeeTime.Time    = new DateTime(((TimeSpan)reader[1]).Ticks);
                    requestedTeeTime.Golfer1 = !DBNull.Value.Equals(reader[2])
                        ? _userManager.GetUserFromId((string)reader[2])
                        : new Shareholder();
                    requestedTeeTime.Golfer2 = !DBNull.Value.Equals(reader[3])
                        ? _userManager.GetUserFromId((string)reader[3])
                        : new Shareholder();
                    requestedTeeTime.Golfer3 = !DBNull.Value.Equals(reader[4])
                        ? _userManager.GetUserFromId((string)reader[4])
                        : new Shareholder();
                    requestedTeeTime.Golfer4 = !DBNull.Value.Equals(reader[5])
                        ? _userManager.GetUserFromId((string)reader[5])
                        : new Shareholder();
                    requestedTeeTime.BookerId = !DBNull.Value.Equals(reader[6])
                        ? (string)reader[6]
                        : " ";
                    requestedTeeTime.Golfer1CheckedIn = (bool)reader[7];
                    requestedTeeTime.Golfer2CheckedIn = (bool)reader[8];
                    requestedTeeTime.Golfer3CheckedIn = (bool)reader[9];
                    requestedTeeTime.Golfer4CheckedIn = (bool)reader[10];
                }
            }
            reader.Close();
            return(requestedTeeTime);
        }
        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);
            }
        }
Exemplo n.º 4
0
        public DailyTeeSheet GetDailyTeeSheet(DateTime dailyTeeSheetDate, ClubBaistUser authenticatedUser)
        {
            var requestedTeeTimesByDate = new List <TeeTime>();

            using var connection = new SqlConnection(ConnectionString);
            using var command    = new SqlCommand("GetTeeTimesByDate", connection);
            command.CommandType  = CommandType.StoredProcedure;
            command.Parameters.Add("@Date", SqlDbType.VarChar).Value = dailyTeeSheetDate;

            //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 teeTimeDbInstance = new TeeTime
                    {
                        Date    = (DateTime)reader[0],
                        Time    = new DateTime(((TimeSpan)reader[1]).Ticks),
                        Golfer1 = !DBNull.Value.Equals(reader[2])
                            ? _userManager.GetUserFromId((string)reader[2])
                            : new Shareholder(),
                        Golfer2 = !DBNull.Value.Equals(reader[3])
                            ? _userManager.GetUserFromId((string)reader[3])
                            :  new Shareholder(),
                        Golfer3 = !DBNull.Value.Equals(reader[4])
                            ? _userManager.GetUserFromId((string)reader[4])
                            :  new Shareholder(),
                        Golfer4 = !DBNull.Value.Equals(reader[5])
                            ? _userManager.GetUserFromId((string)reader[5])
                            : new Shareholder(),
                    };
                    var teeSheetDay = teeTimeDbInstance.Date.DayOfWeek;
                    var teeTime     = teeTimeDbInstance.Time;

                    if (teeSheetDay == DayOfWeek.Saturday || teeSheetDay == DayOfWeek.Sunday)
                    {
                        if (teeTime >= authenticatedUser.weekendHolidayPlayingHoursAfter)
                        {
                            requestedTeeTimesByDate.Add(teeTimeDbInstance);
                        }
                    }
                    else
                    {
                        if (!(authenticatedUser.regularPlayingHoursBefore < teeTime &&
                              authenticatedUser.regularPlayingHoursAfter > teeTime))
                        {
                            requestedTeeTimesByDate.Add(teeTimeDbInstance);
                        }
                    }
                }
            }
            reader.Close();
            return(new DailyTeeSheet(requestedTeeTimesByDate)
            {
                Date = dailyTeeSheetDate
            });
        }