/// <summary> /// The ensure dates passed from the <see cref="OfferSettingsDisplay"/> are applied safely /// </summary> /// <param name="offerSettings"> /// The offer settings. /// </param> /// <param name="settings"> /// The settings. /// </param> /// <returns> /// The <see cref="IOfferSettings"/>. /// </returns> public static void ApplySafeDates(this IOfferSettings offerSettings, OfferSettingsDisplay settings) { if (!settings.OfferExpires) { offerSettings.OfferStartsDate = DateTime.MinValue; offerSettings.OfferEndsDate = DateTime.MaxValue; } else { //// TODO figure out a better way to do this. //// This is a hack fix for the possible difference between the date format configured in the back office //// and the datetime format configured on the server. //if (!string.IsNullOrEmpty(settings.DateFormat)) //{ // var format = settings.DateFormat.Replace("-", "/"); // var startDate = settings.OfferStartsDate.ToShortDateString(); // var expiresDate = settings.OfferEndsDate.ToShortDateString(); // settings.OfferStartsDate = DateTime.ParseExact(startDate, format, CultureInfo.InvariantCulture); // settings.OfferEndsDate = DateTime.ParseExact(expiresDate, format, CultureInfo.InvariantCulture); //} // make sure the ends date is after the start date if (settings.OfferEndsDate < settings.OfferStartsDate) { var temp = settings.OfferEndsDate; settings.OfferEndsDate = settings.OfferStartsDate; settings.OfferStartsDate = temp; } offerSettings.OfferStartsDate = settings.OfferStartsDate; offerSettings.OfferEndsDate = settings.OfferEndsDate; } }
/// <summary> /// Maps a <see cref="OfferSettingsDisplay"/> to a <see cref="IOfferSettings"/> /// </summary> /// <param name="settings"> /// The settings. /// </param> /// <param name="destination"> /// The destination. /// </param> /// <returns> /// The <see cref="IOfferSettings"/>. /// </returns> public static IOfferSettings ToOfferSettings(this OfferSettingsDisplay settings, IOfferSettings destination) { destination.Active = settings.Active; destination.Name = settings.Name; destination.OfferCode = settings.OfferCode; destination.ApplySafeDates(settings); destination.ComponentDefinitions = settings.ComponentDefinitions.AsOfferComponentDefinitionCollection(); return(destination); }
public OfferSettingsDisplay PutUpdateOfferSettings(OfferSettingsDisplay settings) { var offerSettings = _offerSettingsService.GetByKey(settings.Key); if (offerSettings == null) { throw new NullReferenceException("OfferSettings was not found"); } offerSettings = settings.ToOfferSettings(offerSettings); _offerSettingsService.Save(offerSettings); return offerSettings.ToOfferSettingsDisplay(); }
public OfferSettingsDisplay PostAddOfferSettings(OfferSettingsDisplay settings) { var offerSettings = _offerSettingsService.CreateOfferSettings( settings.Name, settings.OfferCode, settings.OfferProviderKey, settings.ComponentDefinitions.AsOfferComponentDefinitionCollection()); offerSettings.Active = settings.Active; offerSettings.ApplySafeDates(settings); _offerSettingsService.Save(offerSettings); return offerSettings.ToOfferSettingsDisplay(); }