public ActionResult destination(string keyname) { string IetfLanguageTag = System.Threading.Thread.CurrentThread.CurrentCulture.IetfLanguageTag; var destinationInfo = (from d in db.cg_Destinations where d.Name.ToLower() == keyname.ToLower() from l in db.cg_Languages where l.SystemLocale.ToLower() == IetfLanguageTag.ToLower() from di in d.cg_Destinations_Info where di.LanguageId == l.LanguageId select di).FirstOrDefault(); if (destinationInfo == null) destinationInfo = new cg_Destinations_Info(); return View(destinationInfo); }
public ProductSearchResultPage searchProducts(string tag, string destinationUrlCustomSegment, long activityId) { HttpRequest Request = HttpContext.Current.Request; HttpResponse Response = HttpContext.Current.Response; ProductSearchResultPage resultPage = new ProductSearchResultPage(); string IetfLanguageTag = System.Threading.Thread.CurrentThread.CurrentCulture.IetfLanguageTag; var defaultCulture = ConfigurationManager.AppSettings["defaultLocale"]; long defaultLanguageId = db.cg_Languages.FirstOrDefault(l => l.SystemLocale == defaultCulture).LanguageId; var language = db.cg_Languages.FirstOrDefault(l => l.SystemLocale.ToLower() == IetfLanguageTag.ToLower()); var destinationInfo = new cg_Destinations_Info(); List<string> excludedActivityStringIds = new List<string>(); List<long> excludedActivityIds = new List<long>(); string orderBy = "price"; if (Request.QueryString["sort"] != null) { orderBy = Request.QueryString["sort"]; } // filters string nameFilter = Request.QueryString["src_productName"]; string codeFilter = Request.QueryString["src_productCode"]; string tagFilter = tag; string budgetFilter = Request.QueryString["budget"]; string departureFilter = Request.QueryString["dep"]; // get the product results var items = searchProductItems(); var AllItems = items; var AllItems_Tagged = items; if ((!String.IsNullOrEmpty(destinationUrlCustomSegment)) && (destinationUrlCustomSegment != "all")) { destinationInfo = db.cg_Destinations_Info.FirstOrDefault(di => (di.UrlCustomSegment.ToLower() == destinationUrlCustomSegment.ToLower() || di.Name.ToLower() == destinationUrlCustomSegment.ToLower()) && (di.LanguageId == language.LanguageId || di.LanguageId == defaultLanguageId)); items = items.Where(p => p.Destination.UrlCustomSegment.ToLower() == destinationUrlCustomSegment.ToLower()); } if (!String.IsNullOrEmpty(nameFilter)) { items = items.Where(p => p.ProductInfo.Title.ToLower().Contains(nameFilter.ToLower()) == true); } if (!String.IsNullOrEmpty(codeFilter)) { items = items.Where(p => p.Product.ProductCode.ToLower().Contains(codeFilter.ToLower()) == true); } if ((!String.IsNullOrEmpty(departureFilter)) && (departureFilter != "all")) { DateTime dfDeparture = Convert.ToDateTime(departureFilter); items = items.Where(p => p.Product.cg_Products_Dates.Where(dd => dd.DepartureDate.Year == dfDeparture.Year && dd.DepartureDate.Month == dfDeparture.Month).Count() > 0 || p.AllYearRound == 1); items = from prodResults in items select new ProductSearchResult { Product = prodResults.Product, AllYearRound = prodResults.AllYearRound, FirstDate = prodResults.Product.cg_Products_Dates.Where(dd => dd.DepartureDate.Year == dfDeparture.Year && dd.DepartureDate.Month == dfDeparture.Month).OrderBy(d => d.DepartureDate).FirstOrDefault(), CheapestDate = prodResults.Product.cg_Products_Dates.Where(dd => dd.DepartureDate.Year == dfDeparture.Year && dd.DepartureDate.Month == dfDeparture.Month).OrderBy(d => d.Price).FirstOrDefault(), ProductInfo = prodResults.ProductInfo, FirstPhoto = prodResults.FirstPhoto, Destination = prodResults.Destination, TagsMap = prodResults.TagsMap, ActivitiesMap = prodResults.ActivitiesMap, Language = prodResults.Language, Duration = (int)prodResults.Duration }; } if ((!String.IsNullOrEmpty(budgetFilter)) && (budgetFilter != "all")) { Decimal iBudget = Convert.ToDecimal(budgetFilter); items = from p in items where p.Product.cg_Products_Dates.Where(dd => dd.Price <= iBudget).Count() > 0 || (p.AllYearRound == 1 && p.Product.Price <= iBudget) select p; } if ((!String.IsNullOrEmpty(tagFilter)) && (tagFilter != "all")) { List<string> tagFilterList = tag.Split(',').ToList(); //cg_Products_Tags ptag = db.cg_Products_Tags.Where(t => t.Tag.ToLower() == tagFilter.ToLower()).FirstOrDefault(); /*cg_Products_Tags ptag = (from ptags in db.cg_Products_Tags join tagFilterItem in tagFilterList on ptags.Tag.ToLower() equals tagFilterItem.ToLower() select ptags).FirstOrDefault();*/ var ptags = from ptg in db.cg_Products_Tags.ToList() join tagFilterItem in tagFilterList on ptg.Tag.ToLower() equals tagFilterItem.ToLower() select ptg; if (ptags.Count() > 0) { foreach (var ptag in ptags) { var tid = ptag.ProductTagId; items = items.Where(p => p.TagsMap.Where(tm => tm.cg_Products_Tags.ProductTagId == tid).Count() > 0); AllItems_Tagged = AllItems.Where(p => p.TagsMap.Where(tm => tm.cg_Products_Tags.ProductTagId == tid).Count() > 0); if ((ptag.EcludedCategories != null) && (ptag.EcludedCategories.Length > 0)) { excludedActivityStringIds.AddRange(ptag.EcludedCategories.Split(',')); } } foreach (var excludedId in excludedActivityStringIds) { long aid = 0; if (long.TryParse(excludedId, out aid)) { excludedActivityIds.Add(aid); } } long firstTagId = ptags.FirstOrDefault().ProductTagId; resultPage.SelectedTagInfo = (from pt in db.cg_Products_Tags where pt.ProductTagId == firstTagId from pti in pt.cg_Products_Tags_Info where pti.LanguageId == language.LanguageId select pti).FirstOrDefault(); } } if (activityId > 0) { cg_Activities activity = db.cg_Activities.Where(a => a.ActivityId == activityId).FirstOrDefault(); if (activity != null) { activity.cg_Products_Activities_Map.Load(); items = items.Where(p => p.ActivitiesMap.Where(am => am.cg_Activities.ActivityId == activity.ActivityId).Count() > 0); } else { items = null; } } resultPage.Activities = (from prods in items from amaps in prods.ActivitiesMap from ai in amaps.cg_Activities.cg_Activities_Info where ai.LanguageId == (amaps.cg_Activities.cg_Activities_Info.Where(inf => inf.LanguageId == language.LanguageId).Count() > 0 ? language.LanguageId : defaultLanguageId) select ai).Distinct().OrderBy(a => a.Name).ToList().Where(a => !excludedActivityIds.Contains(a.ActivityId)); resultPage.Activities_All = (from prods in AllItems_Tagged from amaps in prods.ActivitiesMap from ai in amaps.cg_Activities.cg_Activities_Info where ai.LanguageId == (amaps.cg_Activities.cg_Activities_Info.Where(inf => inf.LanguageId == language.LanguageId).Count() > 0 ? language.LanguageId : defaultLanguageId) select ai).Distinct().OrderBy(a => a.Name); /* (from a in db.cg_Activities from l in db.cg_Languages where l.SystemLocale.ToLower() == IetfLanguageTag.ToLower() from ai in a.cg_Activities_Info where ai.LanguageId == (a.cg_Activities_Info.Where(inf => inf.LanguageId == l.LanguageId).Count() > 0 ? l.LanguageId : defaultLanguageId) select ai).Distinct().OrderBy(a => a.Name); */ resultPage.Destinations = (from d in db.cg_Destinations from di in d.cg_Destinations_Info where di.LanguageId == (d.cg_Destinations_Info.Where(inf => inf.LanguageId == language.LanguageId).Count() > 0 ? language.LanguageId : defaultLanguageId) select di).Distinct().OrderBy(d => d.Name); var photoType = "destination"; long photoParentId = destinationInfo.DestinationId; /* try { if ((!String.IsNullOrEmpty(tagFilter)) && (tagFilter != "all")) { photoType = "activity"; photoParentId = activityId; } else if (destinationInfo != null) { photoType = "destination"; photoParentId = destinationInfo.DestinationId; } } catch { } */ resultPage.SitePhotos = (from sp in db.cg_SitePhotos where sp.ParentId == photoParentId && sp.PhotoType == photoType select sp).OrderBy(sp => sp.ListOrder); if (orderBy == "date") { resultPage.Products = items.OrderByDescending(p => p.AllYearRound).ThenBy(p => p.FirstDate.DepartureDate); } else // by price { resultPage.Products = items.OrderBy(p => p.CheapestDate.Price).ThenBy(p => p.Product.AllYearRound == true); } resultPage.SelectedDestination = destinationInfo; return resultPage; }
/// <summary> /// Deprecated Method for adding a new object to the cg_Destinations_Info EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddTocg_Destinations_Info(cg_Destinations_Info cg_Destinations_Info) { base.AddObject("cg_Destinations_Info", cg_Destinations_Info); }
/// <summary> /// Create a new cg_Destinations_Info object. /// </summary> /// <param name="destinationInfoId">Initial value of the DestinationInfoId property.</param> /// <param name="destinationId">Initial value of the DestinationId property.</param> /// <param name="languageId">Initial value of the LanguageId property.</param> public static cg_Destinations_Info Createcg_Destinations_Info(global::System.Int64 destinationInfoId, global::System.Int64 destinationId, global::System.Int64 languageId) { cg_Destinations_Info cg_Destinations_Info = new cg_Destinations_Info(); cg_Destinations_Info.DestinationInfoId = destinationInfoId; cg_Destinations_Info.DestinationId = destinationId; cg_Destinations_Info.LanguageId = languageId; return cg_Destinations_Info; }
public ActionResult destinations_info_new(FormCollection collection) { long DestinationId = Convert.ToInt64(collection["DestinationId"]); cg_Destinations item = db.cg_Destinations.Where(dest => dest.DestinationId == DestinationId).FirstOrDefault(); cg_Destinations_Info itemInfo = new cg_Destinations_Info(); // add values itemInfo.Name = collection["Title"]; itemInfo.Description = collection["Description"]; itemInfo.DestinationId = DestinationId; itemInfo.MetaDescription = collection["MetaDescription"]; itemInfo.MetaKeywords = collection["MetaKeywords"]; itemInfo.MetaTitle = collection["MetaTitle"]; itemInfo.UrlCustomSegment = collection["UrlCustomSegment"].ToLower(); itemInfo.ShortDescription = collection["ShortDescription"]; itemInfo.LanguageId = Convert.ToInt64(collection["LanguageId"]); itemInfo.cg_DestinationsReference.EntityKey = new System.Data.EntityKey("caval_goEntities.cg_Destinations", "DestinationId", Convert.ToInt64(collection["DestinationId"])); // add to DB & save db.AddTocg_Destinations_Info(itemInfo); db.SaveChanges(); return RedirectToAction("destination_infos", new { id = DestinationId }); }