Example #1
0
 public static MvcHtmlString GetEventsNearYou(this HtmlHelper helper, EventsNearYou Model, int eventId)
 {
     DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0, DateTimeKind.Utc);
     string str = string.Empty;
     string starttime = string.Empty;
     string endtime = string.Empty;
     string resource = helper.GetResource("TimeSeperator");
     string sep = helper.GetResource("DateSeperator");
     if (Model.Events[eventId].EventDateStart.ToShortDateString() != DateTime.MinValue.ToShortDateString())
     {
         try
         {
             if (Model.Events[eventId].EventDateStart.ToShortDateString() != time.ToShortDateString())
             {
                 starttime = SetDateStringFormatted(Model.Events[eventId].EventDateStart, Model.Events[eventId].UseStartTime, resource);
             }
         }
         catch
         {
         }
         try
         {
             if (Model.Events[eventId].EventDateEnd.ToShortDateString() != time.ToShortDateString())
             {
                 endtime = SetDateStringFormatted(Model.Events[eventId].EventDateEnd, Model.Events[eventId].UseEndTime, resource);
             }
         }
         catch
         {
         }
         str = SetTotalString(starttime, endtime, sep);
     }
     else
     {
         bool useEndTime = Model.Events[eventId].UseEndTime;
         str = SetRecurring(Model.Events[eventId].RecuringDays, new TimeSpan?(Model.Events[eventId].RecuringAt), resource, Model.Events[eventId].EventDateEnd, useEndTime, "until");
     }
     return new MvcHtmlString(str);
 }
 public ActionResult Index(IComponentPresentation componentPresentation)
 {
     Stopwatch stopwatch = new Stopwatch();
     if (this.Logger.IsDebugEnabled)
     {
         stopwatch.Start();
         this.Logger.Debug("EventsNearYou enter >>>>>");
     }
     EventsNearYou model = new EventsNearYou {
         ComponentTitle = componentPresentation.Component.Fields["title"].Value,
         Lat = this.Latitude.ToString(),
         Lng = this.Longitude.ToString()
     };
     try
     {
         IField field = componentPresentation.Component.Fields["link"];
         IFieldSet set = field.EmbeddedValues[0];
         if (set.ContainsKey("linkTitle"))
         {
             model.LinkTitle = set["linkTitle"].Value;
         }
         if (set.ContainsKey("linkURL"))
         {
             model.LinkURL = set["linkURL"].Value.ToUpper().StartsWith("HTTP") ? set["linkURL"].Value : set["linkURL"].Value.AddApplicationRoot();
         }
         if (set.ContainsKey("linkComponent"))
         {
             IComponent component = set["linkComponent"].LinkedComponentValues[0];
             model.LinkComponent = component;
         }
     }
     catch
     {
         model.LinkTitle = string.Empty;
         model.LinkURL = string.Empty;
     }
     List<CraftsEvent> craftsEventsInArea = new List<CraftsEvent>();
     if (base.User.Identity.IsAuthenticated)
     {
         decimal num;
         decimal num2;
         MvcApplication.CraftsPrincipal user = (MvcApplication.CraftsPrincipal) base.HttpContext.User;
         if (!decimal.TryParse(user.LAT, out num))
         {
             num = 0.0M;
         }
         if (!decimal.TryParse(user.LONG, out num2))
         {
             num2 = 0.0M;
         }
         if ((num != 0M) && (num2 != 0M))
         {
             if (this.Logger.IsDebugEnabled)
             {
                 this.Logger.DebugFormat("Getting events for user {0} who has long {1} and lat {2}", new object[] { user.UserName, num2, num });
             }
             craftsEventsInArea = this.eventsrepository.GetCraftsEventsInArea(num, num2, this.settings.EventsNearYouRadius, this.settings.EventsNearYouMaxResults);
         }
     }
     if (craftsEventsInArea.Count == 0)
     {
         if (this.GeoDataAvailable)
         {
             if (this.Logger.IsDebugEnabled)
             {
                 this.Logger.DebugFormat("No user available, but request has geo data available, getting events for  long {0} and lat {1}", new object[] { this.Longitude, this.Latitude });
             }
             craftsEventsInArea = this.eventsrepository.GetCraftsEventsInArea(this.Latitude, this.Longitude, this.settings.EventsNearYouRadius, this.settings.EventsNearYouMaxResults);
         }
         else
         {
             if (this.Logger.IsDebugEnabled)
             {
                 this.Logger.Debug("No user available and no request geo data either, just getting some events!");
             }
             craftsEventsInArea = this.eventsrepository.GetCraftsEventsInArea();
         }
     }
     if (this.Logger.IsDebugEnabled)
     {
         this.Logger.DebugFormat("Events: {0}", new object[] { craftsEventsInArea.Count });
     }
     model.Events = craftsEventsInArea;
     if (this.Logger.IsDebugEnabled)
     {
         this.Logger.Debug("<<<<< EventsNearYou finish");
     }
     if (this.Logger.IsDebugEnabled)
     {
         stopwatch.Stop();
         string str = stopwatch.Elapsed.ToString();
         this.Logger.DebugFormat("EventsNearYouController.Index time elapsed:" + str, new object[0]);
     }
     return base.View(model);
 }