//POST protected override DriverResult Editor(DiscountPart part, IUpdateModel updater, dynamic shapeHelper) { var model = new DiscountEditorViewModel(); if (updater.TryUpdateModel(model, Prefix, null, null)) { part.Name = model.Name; part.Record.Discount = model.Discount; var currentCulture = Services.WorkContext.CurrentCulture; var cultureInfo = CultureInfo.GetCultureInfo(currentCulture); var timeZone = Services.WorkContext.CurrentTimeZone; if (!String.IsNullOrWhiteSpace(model.StartDate)) { DateTime startDate; var parseStartDateTime = String.Concat(model.StartDate, " ", model.StartTime); if (DateTime.TryParse(parseStartDateTime, cultureInfo, DateTimeStyles.None, out startDate)) { part.StartDate = TimeZoneInfo.ConvertTimeToUtc(startDate, timeZone); } } else { part.StartDate = null; } if (!String.IsNullOrWhiteSpace(model.EndDate)) { DateTime endDate; var parseEndDateTime = String.Concat(model.EndDate, " ", model.EndTime); if (DateTime.TryParse(parseEndDateTime, cultureInfo, DateTimeStyles.None, out endDate)) { part.EndDate = TimeZoneInfo.ConvertTimeToUtc(endDate, timeZone); } } else { part.EndDate = null; } part.StartQuantity = model.StartQuantity; part.EndQuantity = model.EndQuantity; part.Roles = model.DiscountRoles; part.Pattern = model.Pattern; part.Comment = model.Comment; } return(Editor(part, shapeHelper)); }
//POST protected override DriverResult Editor(DiscountPart part, IUpdateModel updater, dynamic shapeHelper) { var model = new DiscountEditorViewModel(); if (updater.TryUpdateModel(model, Prefix, null, null)) { part.Name = model.Name; string discountString = model.Discount; double percent; double discount; if (!String.IsNullOrEmpty(discountString)) { if (discountString.Trim().EndsWith("%")) { if (double.TryParse(discountString.Substring(0, discountString.Length - 1), out percent)) { part.DiscountPercent = percent; } } else { if (double.TryParse(discountString, out discount)) { part.Discount = discount; } } } var currentCulture = Services.WorkContext.CurrentCulture; var cultureInfo = CultureInfo.GetCultureInfo(currentCulture); var timeZone = Services.WorkContext.CurrentTimeZone; if (!String.IsNullOrWhiteSpace(model.StartDate)) { DateTime startDate; var parseStartDateTime = String.Concat(model.StartDate, " ", model.StartTime); if (DateTime.TryParse(parseStartDateTime, cultureInfo, DateTimeStyles.None, out startDate)) { part.StartDate = TimeZoneInfo.ConvertTimeToUtc(startDate, timeZone); } } else { part.StartDate = null; } if (!String.IsNullOrWhiteSpace(model.EndDate)) { DateTime endDate; var parseEndDateTime = String.Concat(model.EndDate, " ", model.EndTime); if (DateTime.TryParse(parseEndDateTime, cultureInfo, DateTimeStyles.None, out endDate)) { part.EndDate = TimeZoneInfo.ConvertTimeToUtc(endDate, timeZone); } } else { part.EndDate = null; } part.StartQuantity = model.StartQuantity; part.EndQuantity = model.EndQuantity; part.Roles = model.DiscountRoles; part.Pattern = model.Pattern; part.ExclusionPattern = model.ExclusionPattern; part.Comment = model.Comment; } return(Editor(part, shapeHelper)); }