コード例 #1
0
        public ActionResult AddCategory(Category c)
        {
            CategoryValidator rules  = new CategoryValidator();
            ValidationResult  result = rules.Validate(c);

            if (result.IsValid)
            {
                cm.CategoryAddBL(c);
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #2
0
        public ActionResult AddCategory(Category p)
        {
            CategoryValidator categoryValidator = new CategoryValidator();
            ValidationResult  results           = categoryValidator.Validate(p);

            if (results.IsValid)
            {
                cm.CategoryAdd(p);
                return(RedirectToAction("GetCategoryList"));
            }
            else
            {
                foreach (var item in results.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #3
0
        public ActionResult EditCategory(Category category)
        {
            CategoryValidator cV      = new CategoryValidator();
            ValidationResult  results = cV.Validate(category);

            if (results.IsValid)
            {
                cm.CategoryUpdate(category);
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (var item in results.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #4
0
        public ActionResult AddCategory(Category parameter)
        {
            CategoryValidator categoryValidator = new CategoryValidator();
            ValidationResult  results           = categoryValidator.Validate(parameter);

            if (results.IsValid)
            {
                _categoryManager.Add(parameter);
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (var item in results.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View(parameter));
        }
コード例 #5
0
        public ActionResult AddCategory(Category p)
        {
            CategoryValidator validations = new CategoryValidator();
            ValidationResult  result      = validations.Validate(p);

            if (result.IsValid)
            {
                cm.AddCategory(p);
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (ValidationFailure item in result.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #6
0
        public ActionResult AddCategory(Category category)
        {
            CategoryValidator categoryValidator = new CategoryValidator();
            ValidationResult  results           = categoryValidator.Validate(category);

            if (results.IsValid)
            {
                categoryManager.Add(category);
                return(RedirectToAction("GetCategoryList"));
            }
            else
            {
                foreach (var result in results.Errors)
                {
                    ModelState.AddModelError(result.PropertyName, result.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #7
0
        public ActionResult Add(Category category)
        {
            CategoryValidator categoryValidator = new CategoryValidator();
            ValidationResult  validationResult  = categoryValidator.Validate(category);

            if (validationResult.IsValid)
            {
                cm.Add(category);
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (var item in validationResult.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #8
0
        public ActionResult Add(Category category)
        {
            CategoryValidator validationRules = new CategoryValidator();
            ValidationResult  result          = validationRules.Validate(category);

            if (result.IsValid)
            {
                categoryManager.Add(category);
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #9
0
        private bool ValidateCategoryInformation()
        {
            // Validate my data and save in the results variable
            CategoryValidator categoryValidator = new CategoryValidator();
            var results = categoryValidator.Validate(this.category);

            // Check if the validator found any validation errors.
            if (results.IsValid == false)
            {
                foreach (ValidationFailure failure in results.Errors)
                {
                    MessageBox.Show($"{ failure.ErrorMessage }", "Category Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #10
0
        public ActionResult AddCategory(Category c)
        {
            //cm.CategoryAddBL(c);
            CategoryValidator categoryValidator = new CategoryValidator();
            ValidationResult  results           = categoryValidator.Validate(c);

            if (results.IsValid)
            {
                cm.CategoryAddBL(c);
                return(RedirectToAction("GetCategoryList"));
            }
            else
            {
                foreach (var error in results.Errors)
                {
                    ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #11
0
        public ActionResult Add(Category category)
        {
            CategoryValidator categoryValidator = new CategoryValidator();

            ValidationResult validationResults = categoryValidator.Validate(category);

            if (validationResults.IsValid)  // kurallardan geçerse ekleme işlemi yap.
            {
                categoryManager.Add(category);
                return(RedirectToAction("GetCategories"));
            }

            foreach (var result in validationResults.Errors)                        // validationResultları gezdik.
            {
                ModelState.AddModelError(result.PropertyName, result.ErrorMessage); // property ismini ve error mesajı yazıldı.
            }


            return(View()); // ekleme işlemini gerçekleştirdikten sonra sayfayı GetCategories'e yönlendir.
        }
コード例 #12
0
        public ActionResult AddCategory(Category p)
        {
            // cm.CategoryAddBL(p);
            CategoryValidator categoryValidator = new CategoryValidator();
            ValidationResult  results           = categoryValidator.Validate(p);

            if (results.IsValid)
            {
                cm.CategoryAdd(p);
                return(RedirectToAction("GetCategoryList"));//ekleme işleminden sonra "" arası metota gönderir
            }
            else
            {
                foreach (var item in results.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #13
0
        public ActionResult UpdateCategory(Category p)
        {
            CategoryValidator validationRules  = new CategoryValidator();
            ValidationResult  validationResult = validationRules.Validate(p);

            if (validationResult.IsValid)
            {
                p.CategoryDate = DateTime.Now;
                cm.UpdateCategoryBl(p);
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (var item in validationResult.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View(cm.GetCategory(p)));
        }
コード例 #14
0
        [HttpPost] /* sayfada bir butona tıklandığında, sayfada bir şeyler post edildiği zaman çalışacak. */
        public ActionResult AddCategory(Category category)
        {
            CategoryValidator categoryValidator = new CategoryValidator();
            /* CategoryValidator sınıfında olan değerlere göre doğruluk kontrolünü gerçekçeleştirilecek değer `category` */
            ValidationResult validationResult = categoryValidator.Validate(category);

            if (validationResult.IsValid)
            {
                cm.CategoryAddBL(category);
                return(RedirectToAction("GetCategoryList")); /* Ekleme işlemi gerçekleştirildikten sonra yönlendirilecek View */
            }
            else
            {
                foreach (var item in validationResult.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #15
0
        public async Task <ActionResult> UpdateCategory(CategoryDetailViewModel model)
        {
            var validator = new CategoryValidator();
            var result    = validator.Validate(model);

            if (result.IsValid)
            {
                var category = mapper.Map <CategoryDTO>(model);
                await categoryService.UpdateCategoryAsync(category);

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                foreach (ValidationFailure _error in result.Errors)
                {
                    ModelState.AddModelError(_error.PropertyName, _error.ErrorMessage);
                }
                return(View(model));
            }
        }
コード例 #16
0
        public ActionResult AddCategory(Category p)
        {
            //cm.CategoryAddBL(p);
            CategoryValidator categoryValidator = new CategoryValidator();
            //validasyon kontrolü categoryvalidator sınıfındaki olan değerlere göre doğruluk kontrolü
            ValidationResult validationResult = categoryValidator.Validate(p);

            if (validationResult.IsValid)//doğrulanmış ise
            {
                cm.CategoryAddBL(p);
                return(RedirectToAction("FetchCategoryList"));
            }
            else
            {
                foreach (var item in validationResult.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #17
0
        public ActionResult AddCategory(Category p)
        {
            CategoryValidator categoryValidator = new CategoryValidator();
            ValidationResult  result            = categoryValidator.Validate(p);

            if (result.IsValid)
            {
                p.CategoryStatus = false;
                p.CategoryDate   = DateTime.Now;
                cm.SetCategory(p);
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #18
0
        public ActionResult AddCategory(Category p)
        {
            //cm.CategoryAddBL(p);
            CategoryValidator categoryValidator = new CategoryValidator();
            ValidationResult  validationResults = categoryValidator.Validate(p); //Burada ValidationResult eklerken dikkat etmek gerekiyor. DataAnatations dan değil FluentVal dan eklememiz gerek. Bunun için NuGetden yüklemeliyiz.

            if (validationResults.IsValid)
            {
                cm.CategoryAddBL(p);
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (var item in validationResults.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);//Burada result listesinden error'ları alarak modele ekleriz.
                    //ve bu mesajları view tarafında gösteririz.
                }
            }
            return(View());
        }
コード例 #19
0
        public ActionResult AddCategory(Category p)
        {
            CategoryValidator categoryValidator = new CategoryValidator();
            ValidationResult  result            = categoryValidator.Validate(p);

            if (result.IsValid)
            {
                cm.CategoryAdd(p);

                return(RedirectToAction("Index", "AdminCategory", new { s = p.CategoryName }));
            }
            else
            {
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }

            return(View());
        }
コード例 #20
0
        [HttpPost] //sayfada bir şey post edilidğinde çalışacak
        public ActionResult AddCategory(Category p)
        {
            //cm.CategoryAddBL(p);
            CategoryValidator categoryValidator = new CategoryValidator();
            ValidationResult  results           = categoryValidator.Validate(p); //ValidationResult türünde results değişkenini oluşturduk ve

            //CategoryValidator sınıfında olan değerlere göre kontrolünü yaptırdık .Validate() ile
            if (results.IsValid)
            {
                cm.CategoryAddBL(p);
                RedirectToAction("GetCategoryList"); //Ekleme işlemi gerçekleştikten sonra
                                                     //içeride girilen metota yönlendirdik
            }
            else
            {
                foreach (var item in results.Errors) //hata mesajlarını tutacağımız döngü
                {
                    ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                }
            }
            return(View());
        }
コード例 #21
0
        public ActionResult CategoryAdd(Category category)
        {
            //categoryManager.CategoryAddBL(category);

            CategoryValidator categoryValidator = new CategoryValidator();
            ValidationResult  results           = categoryValidator.Validate(category);

            if (results.IsValid)
            {
                categoryManager.CategoryAdd(category);
                return(RedirectToAction("GetCategoryList"));//ekleme işlemi tamamlandıktan sonra GetCategoryList aksiyonuna yönlendirdik.
            }
            else
            {
                foreach (var result in results.Errors)
                {
                    ModelState.AddModelError(result.PropertyName, result.ErrorMessage);
                }
            }

            return(View());
        }
コード例 #22
0
        public async Task <IActionResult> Create(CategoryViewModel categoryViewModel)
        {
            var validator = new CategoryValidator(_context.Categories);
            var result    = validator.Validate(categoryViewModel.Category);

            if (result.IsValid)
            {
                _context.Add(categoryViewModel.Category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, item.ErrorMessage);
                }
            }
            categoryViewModel.Parents = new SelectList(_context.Categories.Where(x => x.ParentId == null), "CategoryId", "Name");
            return(View(categoryViewModel));
        }
コード例 #23
0
        public async Task AddCategory(CategoryDto input)
        {
            List <string> errorList = new List <string>();

            var data = new Category
            {
                Name = input.Name
            };

            CategoryValidator categoryValidator = new CategoryValidator();
            ValidationResult  validationResult  = categoryValidator.Validate(data);

            if (!validationResult.IsValid)
            {
                foreach (var failure in validationResult.Errors)
                {
                    errorList.Add(string.Format("{0}", failure.ErrorMessage));
                }
                string errorString = string.Join(" ", errorList.ToArray());
                throw new UserFriendlyException(errorString);
            }
            await _categoryRepository.InsertAsync(data);
        }
コード例 #24
0
        public async Task <IActionResult> Edit(int id, CategoryViewModel categoryViewModel)
        {
            if (id != categoryViewModel.Category.CategoryId)
            {
                return(RedirectToAction("Error", "Home"));
            }
            Category checkCategoryName = await _context.Categories.SingleOrDefaultAsync(x => x.Name == categoryViewModel.Category.Name && x.CategoryId == categoryViewModel.Category.CategoryId);

            var result = new FluentValidation.Results.ValidationResult();//Bypass the name validator and didn't know how to do it any other way

            if (checkCategoryName != null)
            {
                var validator = new EditCategoryValidator();
                result = validator.Validate(categoryViewModel.Category);
            }
            else
            {
                var validator = new CategoryValidator(_context.Categories);
                result = validator.Validate(categoryViewModel.Category);
            }
            if (result.IsValid)
            {
                _context.Update(categoryViewModel.Category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, item.ErrorMessage);
                }
            }
            categoryViewModel.Parents = new SelectList(_context.Categories.Where(x => x.ParentId == null), "CategoryId", "Name", categoryViewModel.Category.ParentId);
            return(View(categoryViewModel));
        }
コード例 #25
0
 public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
 {
     var validator = new CategoryValidator();
     var result = validator.Validate(this);
     return result.Errors.Select(item => new ValidationResult(item.ErrorMessage, new[] { item.PropertyName }));
 }
コード例 #26
0
ファイル: Category.cs プロジェクト: stantoxt/Piranha.vNext
        /// <summary>
        /// Method to validate model
        /// </summary>
        /// <returns>Returns the result of validation</returns>
        protected override FluentValidation.Results.ValidationResult Validate()
        {
            var validator = new CategoryValidator();

            return(validator.Validate(this));
        }