private GenericValidator ValidateImportRequirement(List <ImportRequirementObject> importRequirements)
        {
            var gVal = new GenericValidator();

            try
            {
                foreach (var im in importRequirements)
                {
                    if (im.ImportStageId < 1)
                    {
                        gVal.Code  = -1;
                        gVal.Error = "Please select Import Stage.";
                        return(gVal);
                    }

                    if (im.DocumentTypeId < 1)
                    {
                        gVal.Code  = -1;
                        gVal.Error = "Please select Document Type.";
                        return(gVal);
                    }
                }
                gVal.Code = 5;
                return(gVal);
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Import Requirement Validation failed. Please provide all required fields and try again.";
                return(gVal);
            }
        }
示例#2
0
        public ActionResult DeleteStoreAddress(long id)
        {
            var gVal = new GenericValidator();

            try
            {
                if (id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = message_Feedback.Invalid_Selection;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var k = new StoreAddressServices().DeleteStoreAddress(id);
                if (k)
                {
                    gVal.Code  = 5;
                    gVal.Error = message_Feedback.Delete_Success;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Delete_Failure;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                gVal.Code  = 5;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
示例#3
0
        private GenericValidator ValidateRegister(RegisterObject register)
        {
            var gVal = new GenericValidator();

            if (register == null)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Fatal_Error;
                return(gVal);
            }
            if (string.IsNullOrEmpty(register.Name))
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Register_Name_Error;
                return(gVal);
            }

            if (register.CurrentOutletId < 1)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Outlet_Selection_Error;
                return(gVal);
            }

            gVal.Code = 5;
            return(gVal);
        }
 public SequenceTransformRule(List <string> values, string path, int next)
 {
     Path      = path;
     Values    = values;
     NextValue = next;
     Validator = new GenericValidator();
 }
示例#5
0
        private GenericValidator ValidateChartOfAccount(ChartOfAccountObject chartOfAccount)
        {
            var gVal = new GenericValidator();

            if (chartOfAccount == null)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Fatal_Error;
                return(gVal);
            }
            if (string.IsNullOrEmpty(chartOfAccount.AccountType))
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Chart_Of_Account_Type_Error;
                return(gVal);
            }
            if (string.IsNullOrEmpty(chartOfAccount.AccountCode))
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Chart_Of_Account_Code_Error;
                return(gVal);
            }
            if (chartOfAccount.AccountGroupId < 1)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Account_Group_Selection_Error;
                return(gVal);
            }

            gVal.Code = 5;
            return(gVal);
        }
 private Result Validate(AgentRoleInfo roleInfo)
 => GenericValidator <AgentRoleInfo> .Validate(v =>
 {
     v.RuleFor(r => r.Name).NotEmpty();
     v.RuleFor(r => r.Permissions).NotEmpty();
 },
                                               roleInfo);
示例#7
0
        public ActionResult GetMyProfile()
        {
            var gVal = new GenericValidator();

            try
            {
                var userInfo = GetSignedOnUser();
                if (userInfo == null || userInfo.UserProfile.Id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Your session has timed out.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var employee = userInfo.Roles.Any(r => r == "Admin") ? new EmployeeServices().GetAdminUserProfile(userInfo.UserProfile.Id) : new EmployeeServices().GetEmployeeByProfile(userInfo.UserProfile.Id);

                if (employee.UserId < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Your profile could not be retrieved.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                Session["_employee"] = employee;
                return(Json(employee, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new EmployeeObject(), JsonRequestBehavior.AllowGet));
            }
        }
示例#8
0
        private GenericValidator ValidateBank(BankObject bank)
        {
            var gVal = new GenericValidator();

            try
            {
                if (string.IsNullOrEmpty(bank.Name))
                {
                    gVal.Code  = -1;
                    gVal.Error = "Please provide Bank Name.";
                    return(gVal);
                }

                if (string.IsNullOrEmpty(bank.SortCode))
                {
                    gVal.Code  = -1;
                    gVal.Error = "Please provide Bank Sort Code.";
                    return(gVal);
                }

                gVal.Code = 5;
                return(gVal);
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Bank Validation failed. Please provide all required fields and try again.";
                return(gVal);
            }
        }
        public ActionResult CheckAddressAvailability()
        {
            var gVal = new GenericValidator();

            try
            {
                var importerInfo = GetLoggedOnUserInfo();
                if (importerInfo.Id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Invalid Operation. Please try again.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var response = new GeneralInformationServices().CheckAddressAvailability(importerInfo.Id);
                gVal.IsAddressProvided = response;
                gVal.Code = response? 5 : -1;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }

            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                gVal.Code  = -1;
                gVal.Error = "An unknown error was encountered. Request could not be serviced. Please try again later.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
        public void Validar(Customer entity)
        {
            GenericValidator<Customer> target = new GenericValidator<Customer>();
            var resultado = target.Validate(entity).ToList();

            resultado.ForEach(x => Console.WriteLine(x.ErrorMessage));
        }
        public ActionResult CheckElligibility()
        {
            var gVal = new GenericValidator();

            try
            {
                var importerInfo = GetLoggedOnUserInfo();
                if (importerInfo.Id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Invalid Operation. Please try again.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var response = new GeneralInformationServices().GetApplicantUnsuppliedDocumentTypes(importerInfo.Id);
                if (!response.Any())
                {
                    gVal.DocumentTypeObjects = new List <DocumentTypeObject>();
                }
                else
                {
                    gVal.DocumentTypeObjects = response;
                }
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }

            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                gVal.Code  = -1;
                gVal.Error = "An unknown error was encountered. Request could not be serviced. Please try again later.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult ProcessGeneralInformation(GeneralInformationObject model)
        {
            var gVal = new GenericValidator();

            try
            {
                var status = ValidateInput(model);
                if (status.Code < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = status.Error;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var response = new GeneralInformationServices().ProcessGeneralInformation(model);

                if (response < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = response == -3 ? "A different Company with the same Name already exists.": "Process failed. Please try again later.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = 5;
                gVal.Error = "Company Information was successfully updated.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                gVal.Code  = -1;
                gVal.Error = "An unknown error was encountered. Please try again";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
        private GenericValidator ValidateProductColumn(ProductColumnObject productColumn)
        {
            var gVal = new GenericValidator();

            try
            {
                if (productColumn.ProductId < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Please select a Product.";
                    return(gVal);
                }

                if (productColumn.CustomCodeId < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Please select Custom Code.";
                    return(gVal);
                }

                gVal.Code = 5;
                return(gVal);
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Product Added Requirement Validation failed. Please provide all required fields and try again.";
                return(gVal);
            }
        }
        public ActionResult DeleteProductColumn(long id)
        {
            var gVal = new GenericValidator();

            try
            {
                if (id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Invalid selection";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }
                var delStatus = new ProductColumnServices().DeleteProductColumn(id);
                if (delStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Product Added Requirement could not be deleted. Please try again later.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = 5;
                gVal.Error = "Product Added Requirement was successfully deleted";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult DeleteDocumentType(long id)
        {
            var gVal = new GenericValidator();

            try
            {
                if (id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = message_Feedback.Invalid_Selection;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var k = new DocumentTypeServices().DeleteDocumentType(id);
                if (k)
                {
                    gVal.Code  = 5;
                    gVal.Error = "Document Type information was successfully deleted.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }
                gVal.Code  = -1;
                gVal.Error = "Document Type information could not be deleted.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                gVal.Code  = 5;
                gVal.Error = "Document Type information could not be deleted.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
示例#16
0
        public GenericValidator EditCompany(ImporterObject company)
        {
            var gVal = new GenericValidator();

            try
            {
                var appStatus = new ImporterServices().UpdateImporter(company);
                if (appStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = appStatus == -2 ? "Company failed. Please try again." : "Company Information already exists";
                    return(gVal);
                }

                gVal.Code  = appStatus;
                gVal.Error = "Company was successfully updated.";
                return(gVal);
            }
            catch (Exception)
            {
                gVal.Error = "Company processing failed. Please try again later";
                gVal.Code  = -1;
                return(gVal);
            }
        }
示例#17
0
        public ActionResult DeleteCustomer(long id, string subdomain)
        {
            var storeSetting = new SessionHelpers().GetStoreInfo(subdomain);

            if (storeSetting == null || storeSetting.StoreId < 1)
            {
                return(Json(new List <ChildMenuObject>(), JsonRequestBehavior.AllowGet));
            }
            var gVal = new GenericValidator();

            try
            {
                var k = new CustomerServices().DeleteCustomer(id);
                if (k)
                {
                    gVal.Code  = 5;
                    gVal.Error = message_Feedback.Delete_Success;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Delete_Failure;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                gVal.Code  = 5;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
示例#18
0
        public ActionResult DeleteDeliveryMethod(long id)
        {
            var gVal = new GenericValidator();

            try
            {
                if (id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = message_Feedback.Invalid_Selection;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var k = new DeliveryMethodServices().DeleteDeliveryMethod(id);
                if (k)
                {
                    gVal.Code  = 5;
                    gVal.Error = message_Feedback.Delete_Success;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Model_State_Error;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                gVal.Code  = 5;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
示例#19
0
        public static string ImportPurchases(VaporStoreDbContext context, string xmlString)
        {
            StringBuilder sb         = new StringBuilder();
            XmlSerializer serializer =
                new XmlSerializer(typeof(ImportPurchaseDto[]), new XmlRootAttribute("Purchases"));

            var purchaseDtos = (ImportPurchaseDto[])serializer.Deserialize(new StringReader(xmlString));

            var validPurchases = new List <Game>();

            foreach (var purchaseDto in purchaseDtos)
            {
                GenericValidator.TryValidate(purchaseDto, out validationTestResults);
                bool isValid = IsValidEnumPurchaseType(purchaseDto.Type);
                if (validationTestResults.Count != 0 || isValid == false)
                {
                    sb.AppendLine("Invalid Data");
                    continue;
                }

                var purchase = CreatePurchase(purchaseDto, context);
                if (purchase.Game == null || purchase.Card == null || purchase.Type == 0)
                {
                    sb.AppendLine("Invalid Data");
                    continue;
                }

                context.Purchases.Add(purchase);
                context.SaveChanges();

                sb.AppendLine($"Imported {purchase.Game.Name} for {purchase.Card.User.Username}");
            }

            return(sb.ToString().TrimEnd());
        }
        public ActionResult EditPurchaseOrder(PurchaseOrderObject purchaseOrder)
        {
            var gVal = new GenericValidator();

            try
            {
                var valStatus = ValidatePurchaseOrder(purchaseOrder);
                if (valStatus.Code < 1)
                {
                    gVal.Code  = 0;
                    gVal.Error = valStatus.Error;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var k = new PurchaseOrderServices().UpdatePurchaseOrder(purchaseOrder);
                if (k < 1)
                {
                    gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Update_Failure;
                    gVal.Code  = 0;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = 5;
                gVal.Error = message_Feedback.Update_Success;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
示例#21
0
        public static string ImportGames(VaporStoreDbContext context, string jsonString)
        {
            StringBuilder sb       = new StringBuilder();
            var           gameDtos = JsonConvert.DeserializeObject <ImportGamesDto[]>(jsonString);

            var validGames = new List <Game>();

            foreach (var gameDto in gameDtos)
            {
                GenericValidator.TryValidate(gameDto, out validationTestResults);

                if (validationTestResults.Count != 0)
                {
                    sb.AppendLine("Invalid Data");
                    continue;
                }

                var game = CreateGame(gameDto, context);
                context.Games.Add(game);
                context.SaveChanges();

                sb.AppendLine($"Added {game.Name} ({game.Genre.Name}) with {game.GameTags.Count} tags");
            }

            return(sb.ToString().TrimEnd());
        }
                public void Serialize(JsonObjectValidator objectValidator,
                                      IFormatter f, JsonSchemaValidationContext c, T o)
                {
                    // Validates fields
                    var validationResults = new Dictionary <string, ValidationResult>();

                    GenericValidator <T> .ValidationResults(
                        objectValidator.Required, objectValidator.Properties,
                        c, o, validationResults);

                    // Serialize fields
                    f.BeginMap(objectValidator.Properties.Count());
                    foreach (var property in objectValidator.Properties)
                    {
                        var fieldName = property.Key;
                        var schema    = property.Value;

                        string[] deps = null;
                        objectValidator.Dependencies.TryGetValue(fieldName, out deps);

                        FieldSerializer fs;
                        if (m_serializers.TryGetValue(fieldName, out fs))
                        {
                            fs(schema, c, f, o, validationResults, deps);
                        }
                    }
                    f.EndMap();
                }
示例#23
0
        public static string ImportUsers(VaporStoreDbContext context, string jsonString)
        {
            StringBuilder sb       = new StringBuilder();
            var           userDtos = JsonConvert.DeserializeObject <ImportUserDto[]>(jsonString);

            foreach (var userDto in userDtos)
            {
                bool isInvalidCardType = ValidateCardType(userDto.Cards);
                GenericValidator.TryValidate(userDto, out validationTestResults);
                var  temp          = validationTestResults;
                bool isInvalidCard = ValidateCards(userDto.Cards);
                if (temp.Count != 0 ||
                    userDto.Cards.Count == 0 ||
                    isInvalidCard ||
                    isInvalidCardType)
                {
                    sb.AppendLine("Invalid Data");
                    continue;
                }

                var user = CreateUser(userDto, context);

                context.Users.Add(user);
                context.SaveChanges();
                sb.AppendLine($"Imported {user.Username} with {user.Cards.Count} cards");
            }

            return(sb.ToString().TrimEnd());
        }
示例#24
0
        private GenericValidator ValidateApplicationIssue(ApplicationIssueObject applicationIssue)
        {
            var gVal = new GenericValidator();
            try
            {
                if (string.IsNullOrEmpty(applicationIssue.ReferenceCode))
                {
                    gVal.Code = -1;
                    gVal.Error = "Please select provide ApplicationIssue.";
                    return gVal;
                }


                gVal.Code = 5;
                return gVal;

            }
            catch (Exception)
            {

                gVal.Code = -1;
                gVal.Error = "ApplicationIssue Validation failed. Please provide all required fields and try again.";
                return gVal;
            }
        }
示例#25
0
        private GenericValidator ValidateBank(BankObject bank)
        {
            var gVal = new GenericValidator();

            if (bank == null)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Fatal_Error;
                return(gVal);
            }
            if (string.IsNullOrEmpty(bank.FullName))
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Bank_Name_Error;
                return(gVal);
            }
            if (string.IsNullOrEmpty(bank.SortCode))
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Bank_Sort_Code_Error;
                return(gVal);
            }
            gVal.Code  = 5;
            gVal.Error = "";
            return(gVal);
        }
示例#26
0
        private GenericValidator ValidateDepotTrunkedOut(DepotTrunkedOutObject depotTrunkedOut)
        {
            var gVal = new GenericValidator();

            try
            {
                if (depotTrunkedOut.DepotId < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Please select a Port.";
                    return(gVal);
                }



                gVal.Code = 5;
                return(gVal);
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "DepotTrunkedOut Validation failed. Please provide all required fields and try again.";
                return(gVal);
            }
        }
示例#27
0
 private static Result Validate(AdministratorRoleInfo roleInfo)
 => GenericValidator <AdministratorRoleInfo> .Validate(v =>
 {
     v.RuleFor(r => r.Name).NotEmpty();
     v.RuleFor(r => r.Permissions).NotEmpty();
 },
                                                       roleInfo);
示例#28
0
        public ActionResult DeleteFaqCategory(long id)
        {
            var gVal = new GenericValidator();

            try
            {
                if (id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Invalid selection";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }
                var delStatus = new FaqCategoryServices().DeleteFaqCategory(id);
                if (delStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "FAQ Category could not be deleted. Please try again later.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = 5;
                gVal.Error = "FAQ Category Information was successfully deleted";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
示例#29
0
        private GenericValidator ValidateCurrency(CurrencyObject currency)
        {
            var gVal = new GenericValidator();

            if (currency == null)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Fatal_Error;
                return(gVal);
            }
            if (string.IsNullOrEmpty(currency.Name))
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Currency_Name_Error;
                return(gVal);
            }
            if (string.IsNullOrEmpty(currency.Symbol))
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Currency_Symbol_Error;
                return(gVal);
            }
            if (currency.CountryId < 1)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Country_Selection_Error;
                return(gVal);
            }

            gVal.Code = 5;
            return(gVal);
        }
示例#30
0
        private GenericValidator ValidateStoreAddress(StoreAddressObject storeAddress)
        {
            var gVal = new GenericValidator();

            if (storeAddress == null)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Fatal_Error;
                return(gVal);
            }
            if (string.IsNullOrEmpty(storeAddress.StreetNo))
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Store_Address_StreetNo_Error;
                return(gVal);
            }

            if (storeAddress.StoreCityId < 1)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.City_Selection_Error;
                return(gVal);
            }

            gVal.Code = 5;
            return(gVal);
        }
        public void ValidateTest()
        {
            var processor = CreateTestableProcessor();
            var results   = GenericValidator.ValidateItem(processor);

            Assert.AreEqual(0, results.Count);
        }