public virtual ByIndexOrNameDictionary <string> ParseParams() { ByIndexOrNameDictionary <string> parameterDictionary = null; if (!string.IsNullOrWhiteSpace(Params)) { string propDisplayName = DataAnnotationsHelper.GetDisplayNameForProperty(this.GetType(), "Params"); string errorMessage = ValidRestParamsAttribute.ParseParams(Params, propDisplayName, out parameterDictionary); if (errorMessage != null) { throw new ArgumentException(errorMessage); } } if (!string.IsNullOrEmpty(XsltName)) { if (parameterDictionary == null) { parameterDictionary = new ByIndexOrNameDictionary <string>(true); } parameterDictionary.Add(CommonQueryParameterKeys.XSLT_RESULTS_TRANSFORMATION_NAME, XsltName); } return(parameterDictionary); }
public static DataTable ToDataTable <T>(this IList <T> list) where T : class, new() { PropertyInfo[] properties = typeof(T).GetProperties(); var displayNameAttributes = DataAnnotationsHelper.GetDisplayNameAttributes(properties); DataTable dataTable = new DataTable(); for (int i = 0; i < properties.Length; i++) { dataTable.Columns.Add(displayNameAttributes[i], Nullable.GetUnderlyingType(properties[i].PropertyType) ?? properties[i].PropertyType); } foreach (T item in list) { DataRow row = dataTable.NewRow(); for (int i = 0; i < properties.Length; i++) { row[displayNameAttributes[i]] = properties[i].GetValue(item) ?? DBNull.Value; } dataTable.Rows.Add(row); } return(dataTable); }
public ActionResult Edit(ConfigScheduleViewModel formModel, string returnUrl) { for (int i = 0; i < formModel.DaysOfWeek.Count; i++) { var dayOfWeek = formModel.DaysOfWeek[i]; if (dayOfWeek.IsBusinessDay) { Match workdayStartRegexMatch = null; Match workdayEndRegexMatch = null; if (string.IsNullOrEmpty(dayOfWeek.WorkdayStartTime)) { this.ModelState.AddModelError(string.Format("DaysOfWeek[{0}].WorkdayStartTime", i), string.Format(ModelStrings.RequiredValidationMessage, DataAnnotationsHelper.GetDisplayName <ConfigScheduleViewModel.DayOfWeek>(model => model.WorkdayStartTime))); } else { workdayStartRegexMatch = TimeDataTypeAttribute.Regex.Match(dayOfWeek.WorkdayStartTime); } if (string.IsNullOrEmpty(dayOfWeek.WorkdayEndTime)) { this.ModelState.AddModelError(string.Format("DaysOfWeek[{0}].WorkdayEndTime", i), string.Format(ModelStrings.RequiredValidationMessage, DataAnnotationsHelper.GetDisplayName <ConfigScheduleViewModel.DayOfWeek>(model => model.WorkdayEndTime))); } else { workdayEndRegexMatch = TimeDataTypeAttribute.Regex.Match(dayOfWeek.WorkdayEndTime); } if (workdayStartRegexMatch == null || workdayEndRegexMatch == null || !workdayStartRegexMatch.Success || !workdayEndRegexMatch.Success) { continue; } int workdayIntegerHourStart = int.Parse(workdayStartRegexMatch.Groups[1].Value) * 100 + int.Parse(workdayStartRegexMatch.Groups[2].Value); int workdayIntegerHourEnd = int.Parse(workdayEndRegexMatch.Groups[1].Value) * 100 + int.Parse(workdayEndRegexMatch.Groups[2].Value); if (workdayIntegerHourStart >= workdayIntegerHourEnd) { this.ModelState.AddModelError(string.Format("DaysOfWeek[{0}].WorkdayEndTime", i), string.Format("O campo '{0}' não pode ter um valor igual ou menor que o do campo '{1}'", DataAnnotationsHelper.GetDisplayName <ConfigScheduleViewModel.DayOfWeek>(model => model.WorkdayEndTime), DataAnnotationsHelper.GetDisplayName <ConfigScheduleViewModel.DayOfWeek>(model => model.WorkdayStartTime))); } // validates lunch time if it exists if (!string.IsNullOrEmpty(dayOfWeek.LunchStartTime) || !string.IsNullOrEmpty(dayOfWeek.LunchEndTime)) { Match lunchStartRegexMatch = null; Match lunchEndRegexMatch = null; if (string.IsNullOrEmpty(dayOfWeek.LunchStartTime)) { this.ModelState.AddModelError(string.Format("DaysOfWeek[{0}].LunchStartTime", i), string.Format(ModelStrings.RequiredValidationMessage, DataAnnotationsHelper.GetDisplayName <ConfigScheduleViewModel.DayOfWeek>(model => model.LunchStartTime))); } else { lunchStartRegexMatch = TimeDataTypeAttribute.Regex.Match(dayOfWeek.LunchStartTime); } if (string.IsNullOrEmpty(dayOfWeek.LunchEndTime)) { this.ModelState.AddModelError(string.Format("DaysOfWeek[{0}].LunchEndTime", i), string.Format(ModelStrings.RequiredValidationMessage, DataAnnotationsHelper.GetDisplayName <ConfigScheduleViewModel.DayOfWeek>(model => model.LunchEndTime))); } else { lunchEndRegexMatch = TimeDataTypeAttribute.Regex.Match(dayOfWeek.LunchEndTime); } // lunch must have a start AND end time. If it's ok, let's continue if (!string.IsNullOrEmpty(dayOfWeek.LunchStartTime) && !string.IsNullOrEmpty(dayOfWeek.LunchEndTime)) { Debug.Assert(lunchStartRegexMatch != null, "lunchStartRegexMatch != null"); var lunchIntegerHourStart = int.Parse(lunchStartRegexMatch.Groups[1].Value) * 100 + int.Parse(lunchStartRegexMatch.Groups[2].Value); Debug.Assert(lunchEndRegexMatch != null, "lunchEndRegexMatch != null"); var lunchIntegerHourEnd = int.Parse(lunchEndRegexMatch.Groups[1].Value) * 100 + int.Parse(lunchEndRegexMatch.Groups[2].Value); if (lunchIntegerHourStart <= workdayIntegerHourStart) { this.ModelState.AddModelError( string.Format("DaysOfWeek[{0}].LunchStartTime", i), string.Format( "O campo '{0}' não pode ter um valor igual ou menor que o do campo '{1}'", DataAnnotationsHelper.GetDisplayName <ConfigScheduleViewModel.DayOfWeek>( model => model.LunchStartTime), DataAnnotationsHelper.GetDisplayName <ConfigScheduleViewModel.DayOfWeek>( model => model.WorkdayStartTime))); } if (lunchIntegerHourEnd >= workdayIntegerHourEnd) { this.ModelState.AddModelError( string.Format("DaysOfWeek[{0}].LunchEndTime", i), string.Format( "O campo '{0}' não pode ter um valor igual ou maior que o do campo '{1}'", DataAnnotationsHelper.GetDisplayName <ConfigScheduleViewModel.DayOfWeek>(model => model.LunchEndTime), DataAnnotationsHelper.GetDisplayName <ConfigScheduleViewModel.DayOfWeek>( model => model.WorkdayEndTime))); } if (lunchIntegerHourStart >= lunchIntegerHourEnd) { this.ModelState.AddModelError( string.Format("DaysOfWeek[{0}].LunchEndTime", i), string.Format( "O campo '{0}' não pode ter um valor igual ou menor que o do campo '{1}'", DataAnnotationsHelper.GetDisplayName <ConfigScheduleViewModel.DayOfWeek>(model => model.LunchEndTime), DataAnnotationsHelper.GetDisplayName <ConfigScheduleViewModel.DayOfWeek>( model => model.LunchStartTime))); } } } } } ; if (this.ModelState.IsValid) { var config = this.Doctor.CFG_Schedule; if (config == null) { config = new CFG_Schedule { PracticeId = this.DbUser.PracticeId, }; this.Doctor.CFG_Schedule = config; } config.AppointmentTime = (int)formModel.AppointmentDuration; config.Sunday = formModel.DaysOfWeek[0].IsBusinessDay; config.SundayWorkdayStartTime = formModel.DaysOfWeek[0].WorkdayStartTime; config.SundayWorkdayEndTime = formModel.DaysOfWeek[0].WorkdayEndTime; config.SundayLunchStartTime = formModel.DaysOfWeek[0].LunchStartTime; config.SundayLunchEndTime = formModel.DaysOfWeek[0].LunchEndTime; config.Monday = formModel.DaysOfWeek[1].IsBusinessDay; config.MondayWorkdayStartTime = formModel.DaysOfWeek[1].WorkdayStartTime; config.MondayWorkdayEndTime = formModel.DaysOfWeek[1].WorkdayEndTime; config.MondayLunchStartTime = formModel.DaysOfWeek[1].LunchStartTime; config.MondayLunchEndTime = formModel.DaysOfWeek[1].LunchEndTime; config.Tuesday = formModel.DaysOfWeek[2].IsBusinessDay; config.TuesdayWorkdayStartTime = formModel.DaysOfWeek[2].WorkdayStartTime; config.TuesdayWorkdayEndTime = formModel.DaysOfWeek[2].WorkdayEndTime; config.TuesdayLunchStartTime = formModel.DaysOfWeek[2].LunchStartTime; config.TuesdayLunchEndTime = formModel.DaysOfWeek[2].LunchEndTime; config.Wednesday = formModel.DaysOfWeek[3].IsBusinessDay; config.WednesdayWorkdayStartTime = formModel.DaysOfWeek[3].WorkdayStartTime; config.WednesdayWorkdayEndTime = formModel.DaysOfWeek[3].WorkdayEndTime; config.WednesdayLunchStartTime = formModel.DaysOfWeek[3].LunchStartTime; config.WednesdayLunchEndTime = formModel.DaysOfWeek[3].LunchEndTime; config.Thursday = formModel.DaysOfWeek[4].IsBusinessDay; config.ThursdayWorkdayStartTime = formModel.DaysOfWeek[4].WorkdayStartTime; config.ThursdayWorkdayEndTime = formModel.DaysOfWeek[4].WorkdayEndTime; config.ThursdayLunchStartTime = formModel.DaysOfWeek[4].LunchStartTime; config.ThursdayLunchEndTime = formModel.DaysOfWeek[4].LunchEndTime; config.Friday = formModel.DaysOfWeek[5].IsBusinessDay; config.FridayWorkdayStartTime = formModel.DaysOfWeek[5].WorkdayStartTime; config.FridayWorkdayEndTime = formModel.DaysOfWeek[5].WorkdayEndTime; config.FridayLunchStartTime = formModel.DaysOfWeek[5].LunchStartTime; config.FridayLunchEndTime = formModel.DaysOfWeek[5].LunchEndTime; config.Saturday = formModel.DaysOfWeek[6].IsBusinessDay; config.SaturdayWorkdayStartTime = formModel.DaysOfWeek[6].WorkdayStartTime; config.SaturdayWorkdayEndTime = formModel.DaysOfWeek[6].WorkdayEndTime; config.SaturdayLunchStartTime = formModel.DaysOfWeek[6].LunchStartTime; config.SaturdayLunchEndTime = formModel.DaysOfWeek[6].LunchEndTime; this.db.SaveChanges(); if (!string.IsNullOrEmpty(returnUrl)) { return(this.Redirect(returnUrl)); } return(this.RedirectToAction("index", "config")); } else { return(this.View(formModel)); } }
private void PrepareValidationRules(ViewContext viewContext, IEnumerable <IDictionary <string, object> > simpleItems) { foreach (IDictionary <string, object> item in simpleItems.Where((IDictionary <string, object> options) => !options.ContainsKey("validationRules"))) { if (item.TryGetValue("dataField", out object value)) { IEnumerable <IDictionary <string, object> > validationRulesByPropertyName = DataAnnotationsHelper.GetValidationRulesByPropertyName(value as string, viewContext); if (validationRulesByPropertyName.Count() > 0) { item.Add("validationRules", validationRulesByPropertyName); } } } }