Example #1
0
        public override void RunRules(IBaseEntity Entity
                                      , EntityRules entitiesRules
                                      , ModelStateDictionary modelState)
        {
            var subCategoryType = GetEntity <SubCategoryType>(entitiesRules);
            var subCategoryItem = GetEntity <SubCategoryClassItem>(entitiesRules);

            if (subCategoryType == null)
            {
                modelState.AddModelError("", "New Order SubCategory must contain one Sub Type");
            }
            if (subCategoryItem == null)
            {
                modelState.AddModelError("", "New Order SubCategory must contain one Sub Item");
            }
        }
Example #2
0
        public static void ValidateStudent(Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary modelState, Student student, IUnitOfWork unitOfWork)
        {
            student.FirstName  = student.FirstName.Trim();
            student.LastName   = student.LastName.Trim();
            student.PersonalNr = student.PersonalNr.Trim();

            if (!String.IsNullOrWhiteSpace(student.PersonalNr) && unitOfWork.StudentRepository.Get(filter: c => c.PersonalNr == student.PersonalNr && c.Id != student.Id).Count() > 0)
            {
                modelState.AddModelError("PersonalNr", "ეს პირადი ნომერი უკვე დარეგისტრირებულია");
            }

            if (student.BirthDate.Date.AddYears(16) > DateTime.Now.Date)
            {
                modelState.AddModelError("BirthDate", "სტუდენტი არ შეიძლება იყოს 16 წელზე პატარა");
            }
        }
Example #3
0
        public static ActionResult Error(
            this ControllerBase controller,
            string error)
        {
            var dict = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary();

            dict.AddModelError("error", error);
            return(controller.BadRequest(dict));
        }
Example #4
0
        public void When_DobVariableGetClassCalled_ReturnCorrectClass(string field, string expected)
        {
            var model = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary();

            model.AddModelError(field, "error");
            var result = HtmlExtensions.GetDOBClass(DobField, DobDay, DobMonth, DobYear, model);

            Assert.AreEqual(result, expected);
        }
Example #5
0
        public void When_GetClassCalledForErrorState_ReturnCorrectClass()
        {
            var model = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary();

            model.AddModelError("test", "error");
            var result = HtmlExtensions.GetClass("test", model);

            Assert.AreEqual(ErrorClass, result);
        }
 //Gérer erreurs AJAX
 public static DataSourceResult ReturnError(Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary ModelState,
                                            ILogger _logger, LogLevel l, string error, string field, string user)
 {
     _logger.Log(l, user + ": " + error);
     ModelState.AddModelError(field, error);
     return(new DataSourceResult
     {
         Errors = error,
         Data = ModelState,
         Total = 1
     });
 }
Example #7
0
        private ActionResult MessagesResponse(string[] messages, enStatusCode statusCode)
        {
            var modelState = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary();
            var prefix     = (statusCode == enStatusCode.Info ? "INFO" : "WARNING");

            foreach (var messageKey in messages)
            {
                var messageValue = this.GetTranslation(messageKey);
                modelState.AddModelError($"{prefix}_{messageKey}", messageValue);
            }
            return(new BadRequestObjectResult(modelState));
        }
Example #8
0
        protected ActionResult ExceptionResponse(Exception ex, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = 0)
        {
            try
            {
                var telemetryProp = new Dictionary <string, string> {
                    { "Exception", ex.Message }, { "CallerMemberName", callerMemberName }, { "CallerFilePath", callerFilePath }, { "CallerLineNumber", callerLineNumber.ToString() }
                };
                if (ex.InnerException != null)
                {
                    telemetryProp.Add("InnerException", ex.InnerException.Message);
                }
                this.TrackException(ex, telemetryProp);
            }
            catch { }

            var modelState = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary();

            modelState.AddModelError("EXCEPTION_", ex.Message);
            if (ex.InnerException != null)
            {
                modelState.AddModelError("INNER_EXCEPTION_", ex.InnerException.Message);
            }
            return(new BadRequestObjectResult(modelState));
        }
Example #9
0
        public static ModelStateDictionary ToModelStateDictionary(this string[] errors)
        {
            if (!errors.IsNullOrEmpty())
            {
                ModelStateDictionary modelStateDictionary = new ModelStateDictionary();

                foreach (string error in errors)
                {
                    modelStateDictionary.AddModelError("", error);
                }

                return(modelStateDictionary);
            }

            return(null);
        }
Example #10
0
        public static ModelStateDictionary ToModelStateDictionary(this ValidationResult validationResult)
        {
            if (!validationResult.IsValid)
            {
                ModelStateDictionary modelStateDictionary = new ModelStateDictionary();

                foreach (var error in validationResult.Errors)
                {
                    modelStateDictionary.AddModelError(error.PropertyName, error.ErrorMessage);
                }

                return(modelStateDictionary);
            }

            return(null);
        }
Example #11
0
        public override void RunRules(IBaseEntity Entity
                                      , EntityRules entitiesRules
                                      , ModelStateDictionary modelState)
        {
            var name = string.Empty;

            var SubCat = GetEntity <SubCategory>(entitiesRules);

            var exists = _ServiceHandlerFactory.Using <ISubCategoryHandler>().Get()
                         .Where(c => c.SubCategoryName.Value == SubCat.SubCategoryName.Value)
                         .AsEnumerable().Any(w => SubCat.IsNew ||
                                             (SubCat.OldPicture != null &&
                                              SubCat.OldPicture.SubCategoryName.Value != w.SubCategoryName.Value));


            if (exists)
            {
                modelState.AddModelError("", "Found Duplicate Sub Category Name");
            }
        }
Example #12
0
        public virtual void RunRulesOnModel(SubCategory Entity, ModelStateDictionary modelState)
        {
            IEnumerable <Category> cats = _ServiceHandlerFactory
                                          .Using <ICategoryHandler>()
                                          .Get();


            var cat_type = _ServiceHandlerFactory
                           .Using <ICategoryTypeHandler>()
                           .Get();


            var subCategory = (SubCategory)Entity;

            if (subCategory.CategoryId.Value == 5 && !subCategory.CategoryTypeId.Value.In(1, 3))
            {
                modelState
                .AddModelError(""
                               , string.Format("Category Type for {0} Must Be XX"
                                               , GetNameValue <Category>(subCategory.CategoryId, cats).CategoryName.Value
                                               )
                               );
            }
        }
Example #13
0
 public void AddError(string key, string errorMessage)
 {
     _modelState.AddModelError(key, errorMessage);
 }
 public static void AddErrorMessage(this Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary modelState, string error)
 {
     modelState.AddModelError("msg", error);
 }