Ejemplo n.º 1
0
    private void FetchAccommodation()
    {
        int accommId = 0;
        int.TryParse(Request["accommid"] == null ? string.Empty : Request["accommid"], out accommId);
        bool admin = User.IsInRole("Administrators");

        accommodation = (from p in dc.Accommodations
                         where p.Id == accommId && (admin || p.Agency.PlaceberryUser.aspnet_User.UserName == User.Identity.Name)
                         select p).SingleOrDefault();

        if (accommodation == null)
        {
            //Ne postoji ili trenutni korisnik nema prava
            Response.Redirect("/manage/customer.aspx");
        }

        aBackToAgency.HRef = String.Format("/manage/Agency.aspx?agencyid={0}", accommodation.AgencyId);
    }
Ejemplo n.º 2
0
    private void FetchAccommodation()
    {
        int languageId = Common.GetLanguageId();

        string accommTag = Common.FixQueryStringUrlTag(Request.QueryString["accommtag"] ?? string.Empty);
        string agencyTag = Common.FixQueryStringUrlTag(Request.QueryString["agencytag"] ?? string.Empty);

        accommodation = (from p in dc.AccommodationUrlTags
                         join q in dc.AgencyUrlTags on p.AgencyId equals q.AgencyId
                         where q.UrlTag == agencyTag && p.UrlTag == accommTag && p.LanguageId == languageId
                         select p.Accommodation).SingleOrDefault();

        if (accommodation == null)
        {
            //Ne postoji
            Response.Redirect("/", true);
        }
    }
Ejemplo n.º 3
0
    protected void btnSave_Command(object sender, CommandEventArgs e)
    {
        string cityentrymode = (string)ViewState["cityentrymode"];

        bool validtest = false;
        Validate("newedit");
        validtest = IsValid;
        if (cityentrymode == "auto")
        {
            Validate("autocity");
            validtest &= IsValid;
        }
        else if (cityentrymode == "manual")
        {
            Validate("manualcity");
            validtest &= IsValid;
        }

        if (validtest)
        {
            switch (e.CommandName)
            {
                case "savenew":
                    accommodation = new UltimateDC.Accommodation();

                    AccommodationCity acccity = new AccommodationCity();
                    dc.AccommodationCities.InsertOnSubmit(acccity);
                    accommodation.AccommodationCity = acccity;
                    AccommodationDescription accdesc = new AccommodationDescription();
                    dc.AccommodationDescriptions.InsertOnSubmit(accdesc);
                    accdesc.Accommodation = accommodation;

                    accdesc.Description = tbxNewDefaultLangDescription.Text.Trim();
                    accdesc.LanguageId = agency.LangaugeId;

                    accommodation.Address = tbxAdress.Text.Trim();
                    accommodation.Agency = agency;
                    accommodation.Name = tbxName.Text.Trim();
                    accommodation.TypeId = int.Parse(ddlType.SelectedValue);
                    accommodation.Active = true;
                    accommodation.IsPublished = false;
                    accommodation.IsDirty = false;

                    accommodation.Pets = chbxPets.Checked;

                    Regex reg1 = new Regex("^([1-9][0-9]*)$");
                    Regex reg2 = new Regex("^(?<min>[1-9][0-9]*)\\s*-\\s*(?<max>[1-9][0-9]*)$");
                    Regex reg3 = new Regex("^(?<min>[1-9][0-9]*)\\s*\\+\\s*(?<max>[1-9][0-9]*)$");
                    string capmin = tbxCapacity.Text.Trim();
                    string capmax = tbxCapacity.Text.Trim();
                    if (reg1.IsMatch(capmax))
                    {
                        accommodation.CapacityMax = int.Parse(capmax);
                    }
                    else if (reg2.IsMatch(capmax))
                    {
                        Match match = reg2.Match(capmin);
                        capmin = match.Groups["min"].Value;

                        match = reg2.Match(capmax);
                        capmax = match.Groups["max"].Value;

                        accommodation.CapacityMin = int.Parse(capmin);
                        accommodation.CapacityMax = int.Parse(capmax);
                    }
                    else if (reg3.IsMatch(capmax))
                    {
                        Match match = reg3.Match(capmin);
                        capmin = match.Groups["min"].Value;

                        match = reg3.Match(capmax);
                        capmax = match.Groups["max"].Value;

                        accommodation.CapacityMin = int.Parse(capmin);
                        accommodation.CapacityMax = int.Parse(capmin) + int.Parse(capmax);
                    }

                    if (cityentrymode == "auto")
                    {
                        int cityId = int.Parse(ddlCityRegion.SelectedValue);

                        string city = dc.GetTraslation(cityId, agency.LangaugeId);
                        var cityparents = dc.GetParents(null, cityId, agency.LangaugeId).ToList();

                        string country = cityparents.Where(i => i.ObjectTypeCode == "COUNTRY").Select(i => i.ParentTitle).SingleOrDefault() ?? string.Empty;
                        string region = cityparents.Where(i => i.ObjectTypeCode == "REGION").Select(i => i.ParentTitle).SingleOrDefault() ?? string.Empty;
                        string subregion = cityparents.Where(i => i.ObjectTypeCode == "SUBREGION").Select(i => i.ParentTitle).SingleOrDefault() ?? string.Empty;
                        string island = cityparents.Where(i => i.ObjectTypeCode == "ISLAND").Select(i => i.ParentTitle).SingleOrDefault() ?? string.Empty;

                        acccity.City = city;
                        acccity.Country = country;
                        acccity.Region = region;
                        acccity.Subregion = subregion;
                        acccity.Island = island;
                        acccity.UltimateTableId = cityId;
                    }
                    else if (cityentrymode == "manual")
                    {
                        acccity.Country = ddlCountry.SelectedItem.Text;
                        acccity.Region = cbxRegion.SelectedItem.Text;
                        acccity.Subregion = cbxSubregion.SelectedItem.Text;
                        acccity.Island = cbxIsland.SelectedItem.Text;
                        acccity.City = cbxCity.SelectedItem.Text;

                        int cityid = 0;
                        int.TryParse(cbxCity.SelectedValue, out cityid);
                        acccity.UltimateTableId = cityid == 0 ? (int?)null : cityid;
                        acccity.PendingApproval = cityid == 0 ? true : false;
                    }

                    dc.SubmitChanges();

                    HttpContext.Current.Items["statusmessage"] = "Uspješan unos!";
                    Server.Transfer(String.Format("/manage/accommodation.aspx?accommid={0}&action=entrysuccess", accommodation.Id));

                    break;
                case "saveedit":

                    accommodation.Name = tbxName.Text;
                    accommodation.TypeId = int.Parse(ddlType.SelectedValue);
                    accommodation.Pets = chbxPets.Checked;
                    accommodation.Address = tbxAdress.Text.Trim();

                    reg1 = new Regex("^([1-9][0-9]*)$");
                    reg2 = new Regex("^(?<min>[1-9][0-9]*)\\s*-\\s*(?<max>[1-9][0-9]*)$");
                    reg3 = new Regex("^(?<min>[1-9][0-9]*)\\s*\\+\\s*(?<max>[1-9][0-9]*)$");

                    capmin = tbxCapacity.Text.Trim();
                    capmax = tbxCapacity.Text.Trim();
                    if (reg1.IsMatch(capmax))
                    {
                        accommodation.CapacityMax = int.Parse(capmax);
                    }
                    else if (reg2.IsMatch(capmax))
                    {
                        Match match = reg2.Match(capmin);
                        capmin = match.Groups["min"].Value;

                        match = reg2.Match(capmax);
                        capmax = match.Groups["max"].Value;

                        accommodation.CapacityMin = int.Parse(capmin);
                        accommodation.CapacityMax = int.Parse(capmax);
                    }
                    else if (reg3.IsMatch(capmax))
                    {
                        Match match = reg3.Match(capmin);
                        capmin = match.Groups["min"].Value;

                        match = reg3.Match(capmax);
                        capmax = match.Groups["max"].Value;

                        accommodation.CapacityMin = int.Parse(capmin);
                        accommodation.CapacityMax = int.Parse(capmin) + int.Parse(capmax);
                    }

                    if (accommodation.IsPublished) accommodation.IsDirty = true;

                    dc.SubmitChanges();

                    HttpContext.Current.Items["statusmessage"] = "Uspješna promjena!";
                    Server.Transfer(String.Format("/manage/accommodation.aspx?accommid={0}&action=entrysuccess", accommodation.Id));

                    break;
                default:
                    break;
            }
        }
    }