Exemplo n.º 1
0
    public StandingReservation ReadStandingReservation(int standingReservationID)
    {
        StandingReservationController standingReservations = new StandingReservationController();
        StandingReservation           sr = standingReservations.SelectStandingReservation(standingReservationID);

        return(sr);
    }
    protected void Approve_Click(object sender, EventArgs e)
    {
        ClubBAIST           cb = new ClubBAIST();
        StandingReservation sr = cb.ReadStandingReservation(int.Parse(Request.QueryString["sr"]));
        bool b = cb.UpdateStandingReservationApproval(sr.StandingReservationID, 1, 1);

        if (!b)
        {
        }
    }
    public List <StandingReservation> SelectStandingReservations(int approved, int active)
    {
        List <StandingReservation> theStandingReservations = new List <StandingReservation>();

        try
        {
            SqlConnection ClubBAISTConnection = new SqlConnection();
            ClubBAISTConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ClubBAIST"].ConnectionString;

            SqlCommand ClubBAISTCommand = new SqlCommand();
            ClubBAISTCommand.CommandType = CommandType.StoredProcedure;
            ClubBAISTCommand.Connection  = ClubBAISTConnection;
            ClubBAISTCommand.CommandText = "SelectStandingReservations";

            SqlParameter parameter = new SqlParameter();
            parameter.ParameterName = "@Approved";
            parameter.SqlDbType     = SqlDbType.Int;
            parameter.Value         = approved;
            parameter.Direction     = ParameterDirection.Input;
            ClubBAISTCommand.Parameters.Add(parameter);

            parameter = new SqlParameter();
            parameter.ParameterName = "@Active";
            parameter.SqlDbType     = SqlDbType.Int;
            parameter.Value         = active;
            parameter.Direction     = ParameterDirection.Input;
            ClubBAISTCommand.Parameters.Add(parameter);

            ClubBAISTConnection.Open();
            SqlDataReader dr;
            dr = ClubBAISTCommand.ExecuteReader();
            while (dr.Read())
            {
                StandingReservation r = new StandingReservation();
                r.StandingReservationID = int.Parse(dr["StandingReservationID"].ToString());
                r.UserID       = int.Parse(dr["UserID"].ToString());
                r.CourseID     = int.Parse(dr["CourseID"].ToString());
                r.ReservedTime = DateTime.Parse(dr["ReservedTime"].ToString());
                r.EndTime      = DateTime.Parse(dr["EndTime"].ToString());
                r.NumberHoles  = int.Parse(dr["NumberHoles"].ToString());
                r.NumberCarts  = int.Parse(dr["NumberCarts"].ToString());
                r.Player2      = dr["Player2"].ToString();
                r.Player3      = dr["Player3"].ToString();
                r.Player4      = dr["Player4"].ToString();
                r.Approved     = int.Parse(dr["Approved"].ToString());
                r.Active       = int.Parse(dr["Active"].ToString());
                theStandingReservations.Add(r);
            }
            ClubBAISTConnection.Close();
        }
        catch (Exception e)
        {
        }
        return(theStandingReservations);
    }
Exemplo n.º 4
0
        public async Task <ActionResult <bool> > ApproveStandingReservation([FromBody] StandingReservation reservationData)
        {
            try
            {
                var isApproved = await this._reservationService.ApproveStandingReservation(reservationData);

                return(isApproved);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
    protected void SubmitButton_Click(object sender, EventArgs e)
    {
        ClubBAIST           cb = new ClubBAIST();
        StandingReservation sr = cb.ReadStandingReservation(int.Parse(Request.QueryString["sr"]));
        bool b = cb.UpdateStandingReservation(int.Parse(Request.QueryString["sr"]), sr.UserID, int.Parse(CourseDD.SelectedValue), DateTime.Parse(TeeTimesDD.SelectedValue), EndCalendar.SelectedDate, int.Parse(NumberHolesDD.SelectedValue), int.Parse(NumberCartsDD.SelectedValue), Player2TB.Text, Player3TB.Text, Player4TB.Text);

        if (!b)
        {
            Response.Write("Something went wrong.");
        }
        else
        {
            Response.Redirect("ViewStandingReservations.aspx");
        }
    }
    private void FillForm()
    {
        //this page will break
        ClubBAIST           cb = new ClubBAIST();
        StandingReservation sr = cb.ReadStandingReservation(int.Parse(Request.QueryString["sr"]));

        Calendar.SelectedDate       = sr.ReservedTime.Date;
        EndCalendar.SelectedDate    = sr.EndTime.Date;
        EndCalendar.VisibleDate     = sr.EndTime.Date;
        NumberHolesDD.SelectedValue = sr.NumberHoles.ToString();
        NumberCartsDD.SelectedValue = sr.NumberCarts.ToString();
        CourseDD.SelectedValue      = sr.CourseID.ToString();
        Player2TB.Text = sr.Player2;
        Player3TB.Text = sr.Player3;
        Player4TB.Text = sr.Player4;
    }
    public StandingReservation SelectStandingReservation(int standingReservationID)
    {
        StandingReservation theStandingReservation = new StandingReservation();

        try
        {
            SqlConnection ClubBAISTConnection = new SqlConnection();
            ClubBAISTConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ClubBAIST"].ConnectionString;

            SqlCommand ClubBAISTCommand = new SqlCommand();
            ClubBAISTCommand.CommandType = CommandType.StoredProcedure;
            ClubBAISTCommand.Connection  = ClubBAISTConnection;
            ClubBAISTCommand.CommandText = "SelectStandingReservation";

            SqlParameter parameter = new SqlParameter();
            parameter.ParameterName = "@StandingReservationID";
            parameter.SqlDbType     = SqlDbType.Int;
            parameter.Value         = standingReservationID;
            parameter.Direction     = ParameterDirection.Input;

            ClubBAISTCommand.Parameters.Add(parameter);

            ClubBAISTConnection.Open();
            SqlDataReader dr;
            dr = ClubBAISTCommand.ExecuteReader();
            dr.Read();

            theStandingReservation.StandingReservationID = int.Parse(dr["StandingReservationID"].ToString());
            theStandingReservation.UserID       = int.Parse(dr["UserID"].ToString());
            theStandingReservation.CourseID     = int.Parse(dr["CourseID"].ToString());
            theStandingReservation.ReservedTime = DateTime.Parse(dr["ReservedTime"].ToString());
            theStandingReservation.EndTime      = DateTime.Parse(dr["EndTime"].ToString());
            theStandingReservation.NumberHoles  = int.Parse(dr["NumberHoles"].ToString());
            theStandingReservation.NumberCarts  = int.Parse(dr["NumberCarts"].ToString());
            theStandingReservation.Player2      = dr["Player2"].ToString();
            theStandingReservation.Player3      = dr["Player3"].ToString();
            theStandingReservation.Player4      = dr["Player4"].ToString();
            theStandingReservation.Approved     = int.Parse(dr["Approved"].ToString());
            theStandingReservation.Active       = int.Parse(dr["Active"].ToString());

            ClubBAISTConnection.Close();
        }
        catch
        {
        }
        return(theStandingReservation);
    }
        public async Task <bool> CreateStandingReservation(ReservationDTO reservationData)
        {
            StandingReservation standingReservation = new StandingReservation()
            {
                StandingReservationId = Guid.NewGuid(),
                UserId          = reservationData.User.UserId,
                StartDate       = reservationData.StartDate,
                EndDate         = reservationData.EndDate,
                CreatedBy       = reservationData.CreatedBy,
                ApprovedBy      = null,
                IsApproved      = false,
                CreatedDateTime = DateTime.UtcNow
            };

            await _context.StandingReservation.AddAsync(standingReservation);

            await _context.SaveChangesAsync();

            return(true);
        }
    protected void DaySelected(object sender, EventArgs e)
    {
        DateTime            selectedDay    = Calendar.SelectedDate;
        ClubBAIST           cb             = new ClubBAIST();
        StandingReservation sr             = cb.ReadStandingReservation(int.Parse(Request.QueryString["sr"]));
        List <Reservation>  TeeTimesForDay = cb.ReadReservationBatchByTimeFrame(selectedDay, selectedDay.AddDays(1));

        TeeTimesDD.Items.Clear();
        DateTime bufferDateTime = selectedDay.AddHours(7.00);
        bool     offset         = true;

        while (bufferDateTime <= selectedDay.AddHours(18))
        {
            ListItem li = new ListItem();
            li.Text  = bufferDateTime.TimeOfDay.ToString();
            li.Value = MakeFormattedDate(bufferDateTime);

            foreach (Reservation r in TeeTimesForDay)
            {
                if (r.ReservedTime == bufferDateTime)
                {
                    li.Attributes.Add("disabled", "true");
                }
            }
            TeeTimesDD.Items.Add(li);
            if (offset)
            {
                bufferDateTime = bufferDateTime.AddMinutes(7.00);
                offset         = false;
            }
            else
            {
                bufferDateTime = bufferDateTime.AddMinutes(8.00);
                offset         = true;
            }
        }
        TeeTimesDD.SelectedValue = MakeFormattedDate(sr.ReservedTime);
    }
        public async Task <bool> ApproveStandingReservation(StandingReservation reservationData)
        {
            var standingReservation = await _context.StandingReservation.Where(x => x.StandingReservationId == reservationData.StandingReservationId)
                                      .Include(x => x.User)
                                      .FirstOrDefaultAsync();

            if (standingReservation == null)
            {
                throw new Exception("Standing reservation not found");
            }

            var approvedByUser = await _context.User.FindAsync(reservationData.ApprovedBy);

            if (approvedByUser == null)
            {
                throw new Exception("User not found");
            }
            using (var transaction = await _context.Database.BeginTransactionAsync())
            {
                try
                {
                    List <DateTimeOffset> reservationStartDates = new List <DateTimeOffset>();

                    reservationStartDates.Add(standingReservation.StartDate);
                    reservationStartDates.Add(standingReservation.StartDate.AddDays(7));
                    reservationStartDates.Add(standingReservation.StartDate.AddDays(14));
                    reservationStartDates.Add(standingReservation.StartDate.AddDays(21));
                    reservationStartDates.Add(standingReservation.EndDate);

                    foreach (var reservationStartDate in reservationStartDates)
                    {
                        Reservation newReservation = new Reservation()
                        {
                            NumberOfPlayers       = 1,
                            Notes                 = null,
                            CreatedBy             = approvedByUser.Email,
                            CreatedDateTime       = DateTime.UtcNow,
                            StartDate             = reservationStartDate,
                            EndDate               = reservationStartDate.AddHours(2),
                            UserId                = standingReservation.UserId,
                            StandingReservationId = standingReservation.StandingReservationId,
                            ReservationId         = Guid.NewGuid(),
                        };

                        await _context.Reservation.AddAsync(newReservation);
                    }

                    standingReservation.IsApproved            = true;
                    standingReservation.ApprovedBy            = approvedByUser.UserId;
                    _context.Entry(standingReservation).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    await transaction.CommitAsync();

                    return(true);
                }
                catch (Exception ex)
                {
                    await transaction.RollbackAsync();

                    throw ex;
                }
            }
        }