public ActionResult Index()
        {
            try
            {
                Files                oFiles     = new Files();
                ValidateCustomer     oCustomers = new ValidateCustomer();
                List <CustomerModel> customers  = new List <CustomerModel>();

                /// check customers data
                customers = oCustomers.Validate(oFiles.ReaderCustomers(SessionApp.GetVarSession("fileCustomers")), oFiles.ReaderContent(SessionApp.GetVarSession("fileContent")));
                /// file name save to session
                SessionApp.SetVarSession("fileResult", "Resultados.txt");
                /// saved to results
                oFiles.SaveCustomers(customers, SessionApp.GetVarSession("fileResult"));

                ViewBag.Message = "Check Customers";
            }
            catch (Exception ex)
            {
                ViewBag.Message = "ERROR: There was an error to validate the files";
                return(RedirectToAction("Index", "Home"));
            }

            return(View());
        }
示例#2
0
        //Use this to add server-side validation
        protected override DbEntityValidationResult ValidateEntity(DbEntityEntry entityEntry, IDictionary <object, object> items)
        {
            //do the base DataAnnotations/fluent validation mapping
            var result = base.ValidateEntity(entityEntry, items);

            List <DbValidationError> checkedItems;

            if (entityEntry.Entity == Customers)
            {
                checkedItems = ValidateCustomer.Validate(entityEntry, items);
                if (checkedItems != null)
                {
                    foreach (var item in checkedItems)
                    {
                        result.ValidationErrors.Add(item);
                    }
                }
            }

            return(result);
        }