Пример #1
0
        /// <summary>
        /// Handle life-cycle event.
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public override bool OnBeforeSave(object ctx)
        {
            if (StartDate == DateTime.MinValue)
            {
                StartDate = DateTime.Now;
            }
            if (EndDate == DateTime.MinValue || EndDate == DateTime.MaxValue)
            {
                EndDate = DateTime.Now;
            }

            this.Description = this.Content.Truncate(_settings.DescriptionLength);
            string tagsfinal = Tags;

            if (!string.IsNullOrEmpty(tagsfinal))
            {
                tagsfinal = tagsfinal.Replace("&", " ");
                tagsfinal = tagsfinal.Replace(",", " ");
                Tags      = tagsfinal;
            }
            ToDo.Implement(ToDo.Priority.Normal, "Kishore", "IsPublished not supported for events.", () => { this.IsPublished = true; this.IsPublic = true; });

            // Form fields might set the country values etc. after the isonline is mapped.
            if (IsOnline)
            {
                _address.IsOnline = true;
            }

            // Set the category id.
            if (!string.IsNullOrEmpty(CategoryName))
            {
                var lookup = Categorys.Category.LookupFor <Event>();
                this.CategoryId = lookup != null && lookup.ContainsKey(CategoryName) ? lookup[CategoryName].Id : 0;
            }
            if (!Settings.EnableFreeformLocations && !IsOnline)
            {
                // Apply the country/state ids.
                IList <string> errors = new List <string>();
                LocationHelper.ApplyCountry(this.Address, ComLib.LocationSupport.Location.CountriesLookup, errors);
                LocationHelper.ApplyState(this.Address, ComLib.LocationSupport.Location.StatesLookup, errors);
                LocationHelper.ApplyCity(this.Address, ComLib.LocationSupport.Location.CitiesLookup, ComLib.LocationSupport.Location.StatesLookup, ComLib.LocationSupport.Location.CountriesLookup);
                foreach (var error in errors)
                {
                    this.Errors.Add(error);
                }
            }
            return(true);
        }