Esempio n. 1
0
        public BsJsonResult Register(AuthenticationModel model)
        {
            //keep errors only for RegisterModel
            ModelState.ClearModelState(model.GetPropertyName(m => m.RegisterModel) + ".");

            //add validation error to BsRange field
            if (model.RegisterModel != null &&
                model.RegisterModel.Interval != null &&
                //model.RegisterModel.Interval.To.ItemValue.HasValue &&
                //model.RegisterModel.Interval.From.ItemValue.HasValue &&
                model.RegisterModel.Interval.From.ItemValue > model.RegisterModel.Interval.To.ItemValue)
            {
                ModelState.AddFieldError("RegisterModel.Interval",
                                         model.RegisterModel.Interval.GetType(),
                                         "Invalid interval");
            }

            //if (model.RegisterModel != null &&
            //   model.RegisterModel.Interval != null &&
            //   model.RegisterModel.Interval.To.ItemValue.HasValue &&
            //   model.RegisterModel.Interval.From.ItemValue.HasValue &&
            //   model.RegisterModel.Interval.From.ItemValue.Value > model.RegisterModel.Interval.To.ItemValue.Value)
            //{
            //    ModelState.AddFieldError("RegisterModel.Interval",
            //        model.RegisterModel.Interval.GetType(),
            //        "Invalid interval");
            //}

            //add validation error to BsSelectList field
            ModelState.AddFieldError("RegisterModel.CountriesList",
                                     model.RegisterModel.CountriesList.GetType(),
                                     "Selected location doesn't match your GPS location");

            //add global validation error
            ModelState.AddFormError("RegisterModel",
                                    "This email address is in use.");

            if (ModelState.IsValid)
            {
            }
            else
            {
                //JSON serialize ModelState errors
                return(new BsJsonResult(
                           new Dictionary <string, object> {
                    { "Errors", ModelState.GetErrors() }
                },
                           BsResponseStatus.ValidationError));
            }

            return(new BsJsonResult());
        }