Beispiel #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            UltimateDataContext dc = new UltimateDataContext();
            Accommodation accommodation;

            int advertId = 0;
            int accommId = 0;

            // booking ce se moc pokretati i preko oglasa i preko agencije (accommodationid)
            if (Int32.TryParse(Request.QueryString["advertid"], out advertId))
            {
                GetAdvertResult advert = dc.GetAdvert(advertId).Single<GetAdvertResult>();

                // nisam siguran da je ovo dobar uvjet!
                if (advert != null && advert.PlaceberryAdvert && advert.AccommodationId.HasValue)
                {
                    accommId = advert.AccommodationId.Value;
                }
            }
            else
            {
                Int32.TryParse(Request.QueryString["accommid"], out accommId);
            }

            if (accommId == 0)
            {
                Response.Redirect("/");
            }

            accommodation = (from a in dc.Accommodations
                             where a.Id == accommId
                             select a).SingleOrDefault();

            if (accommodation == null)
            {
                Response.Redirect("/");
            }

            lblAgencyName.Text = accommodation.Agency.Name == null ? string.Empty : accommodation.Agency.Name;
            lblAccommName.Text = accommodation.Name == null ? string.Empty : accommodation.Name;

            int capMin = accommodation.CapacityMin.HasValue ? accommodation.CapacityMin.Value : 1;
            int capMax = accommodation.CapacityMax.HasValue ? accommodation.CapacityMax.Value : 1;

            for (int i = capMin; i <= capMax; ++i)
            {
                this.ddlNumOfPersons.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }

            for (int i = 0; i <= BookingSessionManager.DEF_MAX_NUM_OF_BABIES; ++i)
            {
                this.ddlNumOfBabies.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }

            bool priceByPerson = false; // ovo se mora nekako postaviti
            _booking = new BookingSessionManager(accommodation.Id, accommodation.Name, accommodation.AgencyId, priceByPerson, true);

            // ukoliko admin kreira i ovdje booking takoder ga spremiti
            if (User.IsInRole("Administrators") || accommodation.Agency.PlaceberryUser.aspnet_User.UserName == User.Identity.Name)
            {
                _booking.SetAdminUserName(User.Identity.Name);
            }

            HttpContext.Current.Session[BookingSessionManager.BOOKING_SESSION_NAME] = _booking;
        }
    }
Beispiel #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            phMainContent.Visible = true;
            phLoadError.Visible = false;

            UltimateDataContext dc = new UltimateDataContext();
            Accommodation accommodation;

            int advertId = 0;
            int accommId = 0;

            // booking ce se moc pokretati i preko oglasa i preko agencije (accommodationid)
            if (Int32.TryParse(Request.QueryString["advertid"], out advertId))
            {
                GetAdvertResult advert = dc.GetAdvert(advertId).Single<GetAdvertResult>();

                // nisam siguran da je ovo dobar uvjet!
                if (advert != null && advert.PlaceberryAdvert && advert.AccommodationId.HasValue)
                {
                    accommId = advert.AccommodationId.Value;
                }
            }
            else if (!Int32.TryParse(Request.QueryString["accommid"], out accommId))
            {
                // OVO JE SADA ZA NOVAKE!
                int itemId;
                if (Int32.TryParse(Request.QueryString["itemid"], out itemId))
                {
                    switch (Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName)
                    {
                        case "hr":
                            accommId = itemId - 2;
                            break;
                        case "en":
                            accommId = itemId + 8;
                            break;
                    }

                    // u bazi su accommodationi od novaka od Id-a 12 do 20 pa treba pripaziti da ne ode na neki drugi
                    if (accommId < 12 || accommId > 20)
                        accommId = 0;
                }
            }

            if (accommId == 0)
            {
                phMainContent.Visible = false;
                phLoadError.Visible = true;
                lblLoadErrorMsg.Text = ERR_MSG_WRONG_PARAMETARS;
                return;
            }

            accommodation = (from a in dc.Accommodations
                             where a.Id == accommId
                             select a).SingleOrDefault();

            if (accommodation == null)
            {
                phMainContent.Visible = false;
                phLoadError.Visible = true;
                lblLoadErrorMsg.Text = ERR_MSG_ACCOMMODATION_NOT_FOUND;
                return;
            }

            lblAppartmentName.Text = accommodation.Name;

            // PROMO CODE
            bool includePromoCode = true;
            if (Boolean.TryParse(Request.QueryString["promocode"], out includePromoCode))
            {
                phPromoCode.Visible = includePromoCode;
            }

            for (int i = BookingSessionManager.DEF_MIN_NUM_OF_NIGHTS; i <= BookingSessionManager.DEF_MAX_NUM_OF_NIGHTS; ++i)
            {
                this.ddlNumOfNights.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }

            int capMin = accommodation.CapacityMin.HasValue ? accommodation.CapacityMin.Value : 1;
            int capMax = accommodation.CapacityMax.HasValue ? accommodation.CapacityMax.Value : 1;

            for (int i = capMin; i <= capMax; ++i)
            {
                this.ddlNumOfPersons.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }

            for (int i = 0; i <= BookingSessionManager.DEF_MAX_NUM_OF_BABIES; ++i)
            {
                this.ddlNumOfBabies.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }

            this.lblPriceSum.Text = "0";
            this.lblNumOfPersons.Text = ddlNumOfPersons.SelectedValue;
            this.lblNumOfBabies.Text = ddlNumOfBabies.SelectedValue;
            this.phPriceByDay.Visible = false;
            this.phNoPrices.Visible = false;

            bool priceByPerson = false; // HARDCODE!!! ovo ce se morat nekako postaviti!
            _bookingSession = new BookingSessionManager(accommodation.Id, accommodation.Name, accommodation.AgencyId, priceByPerson, false);

            // ukoliko admin kreira i ovdje booking takoder ga spremiti
            if (User.IsInRole("Administrators") || accommodation.Agency.PlaceberryUser.aspnet_User.UserName == User.Identity.Name)
            {
                _bookingSession.SetAdminUserName(User.Identity.Name);
            }

            HttpContext.Current.Session[BookingSessionManager.BOOKING_SESSION_NAME] = _bookingSession;
            lbNext.Attributes.Add("onclick", "this.href='#';this.disabled=true;" + Page.ClientScript.GetPostBackEventReference(lbNext, "").ToString());
        }
    }