Beispiel #1
0
        public override async Task UpdateAsync(IRepository <User, Guid> repository)
        {
            var user = await repository.GetAsync(Id);

            user.IsNull().Throw <DataNotFoundException>(Id);

            if (Email.HasValue() && !user.Email.Equals(Email, StringComparison.CurrentCultureIgnoreCase))
            {
                var userSameEmail = await repository.GetFirstAsync(e => e.Email == Email);

                userSameEmail.IsNotNull().Throw <BusinessConflictException>(string.Format(Messages.AlreadyExists, "email"));

                user.Email = Email;
            }

            if (FirstName.HasValue())
            {
                user.FirstName = FirstName;
            }

            if (LastName.HasValue())
            {
                user.LastName = LastName;
            }

            if (Password.HasValue())
            {
                user.Password = Password;
            }

            user.Active  = Active;
            ModifiedDate = DateTime.UtcNow;

            await repository.SaveAsync(user);
        }
        public Expression <Func <Model.President, Boolean> > ToExpression()
        {
            Expression <Func <Model.President, Boolean> > result = null;

            int presidentNumberIntValue = 0;

            if (PresidentNumber.HasValue() && Int32.TryParse(PresidentNumber, out presidentNumberIntValue) && presidentNumberIntValue > 0)
            {
                Expression <Func <Model.President, Boolean> > expr = model => model.PresidentNumber == presidentNumberIntValue;
                result = AppendExpression(result, expr);
            }

            if (FirstName.HasValue())
            {
                Expression <Func <Model.President, Boolean> > expr = model => model.FirstName.Like(FirstName);
                result = AppendExpression(result, expr);
            }

            if (LastName.HasValue())
            {
                Expression <Func <Model.President, Boolean> > expr = model => model.LastName.Like(LastName);
                result = AppendExpression(result, expr);
            }

            if (StartDate.HasValue)
            {
                Expression <Func <Model.President, Boolean> > expr = model => model.TookOffice >= StartDate;
                result = AppendExpression(result, expr);
            }

            if (EndDate.HasValue)
            {
                Expression <Func <Model.President, Boolean> > expr = model => model.LeftOffice <= EndDate;
                result = AppendExpression(result, expr);
            }

            if (Alive.HasValue)
            {
                Expression <Func <Model.President, Boolean> > expr = model => model.IsAlive == Alive;
                result = AppendExpression(result, expr);
            }

            var termCounntIntValue = 0;

            if (TermCount.HasValue() && Int32.TryParse(TermCount, out termCounntIntValue) && termCounntIntValue > 0)
            {
                Expression <Func <Model.President, Boolean> > expr = model => model.Terms.Count() == termCounntIntValue;
                result = AppendExpression(result, expr);
            }

            return(result);
        }
Beispiel #3
0
        public string GetFormattedName()
        {
            var sb = new StringBuilder();

            sb.Append(FirstName);
            if (FirstName.HasValue() && LastName.HasValue())
            {
                sb.Append(" ");
            }
            sb.Append(LastName);

            return(sb.ToString());
        }
Beispiel #4
0
        private void ValidBasic(ModelStateDictionary ModelState, int i)
        {
            if (!FirstName.HasValue())
            {
                ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].FirstName), "first name required");
            }
            if (!LastName.HasValue())
            {
                ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].LastName), "last name required");
            }

            var mindate = DateTime.Parse("1/1/1753");
            int n       = 0;

            if (birthday.HasValue && birthday < mindate)
            {
                ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].DateOfBirth), "invalid date");
            }
            if (birthday.HasValue && birthday > mindate)
            {
                n++;
            }
            if (Util.ValidEmail(EmailAddress))
            {
                n++;
            }
            var d = Phone.GetDigits().Length;

            if (Phone.HasValue() && d >= 10)
            {
                n++;
            }
            if (d > 20)
            {
                ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].Phone), "too many digits in phone");
            }

            if (n == 0)
            {
                ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].DateOfBirth), "we require one of valid birthdate, email or phone to find your record");
            }

            if (!Util.ValidEmail(EmailAddress))
            {
                ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].EmailAddress), "valid email required");
            }
            if (Phone.HasValue() && d < 10)
            {
                ModelState.AddModelError(Parent.GetNameFor(mm => mm.List[i].Phone), "10+ digits required");
            }
        }
Beispiel #5
0
        public override async Task UpdateAsync(IRepository <Employee, Guid> repository)
        {
            var employee = await repository.GetAsync(Id);

            employee.IsNull().Throw <DataNotFoundException>(Id);

            if (Email.HasValue() && !employee.Email.Equals(Email, StringComparison.CurrentCultureIgnoreCase))
            {
                var employeeSameEmail = await repository.GetFirstAsync(e => e.Email == Email);

                employeeSameEmail.IsNotNull().Throw <BusinessConflictException>(string.Format(Messages.AlreadyExists, "email"));

                employee.Email = Email;
            }

            if (FirstName.HasValue())
            {
                employee.FirstName = FirstName;
            }

            if (LastName.HasValue())
            {
                employee.LastName = LastName;
            }

            if (Password.HasValue())
            {
                employee.Password = Password;
            }

            if (IdentityDocument.HasValue())
            {
                employee.IdentityDocument = IdentityDocument;
            }

            if (SocialSecurity.HasValue())
            {
                employee.SocialSecurity = SocialSecurity;
            }

            employee.Active = Active;
            ModifiedDate    = DateTime.UtcNow;

            await repository.SaveAsync(employee);
        }
Beispiel #6
0
        public NameValueCollection BuildQueryString()
        {
            var nv = new NameValueCollection();

            if (Page > 0)
            {
                nv.Add("page", Page.ToString());
            }
            if (Mailbox != null)
            {
                nv.Add("mailbox", Mailbox.ToString());
            }
            if (FirstName.HasValue())
            {
                nv.Add("firstName", FirstName);
            }
            if (LastName.HasValue())
            {
                nv.Add("lastName", LastName);
            }
            if (ModifiedSince != null)
            {
                nv.Add("modifiedSince", ModifiedSince.ToString());
            }

            if (LastName.HasValue())
            {
                nv.Add("lastName", LastName);
            }

            if (SortField.HasValue)
            {
                var field = "";
                switch (SortField)
                {
                case CustomerSearchField.FirstName:
                    field = "firstName";
                    break;

                case CustomerSearchField.LastName:
                    field = "lastName";
                    break;

                case CustomerSearchField.ModifiedAt:
                    field = "modifiedAt";
                    break;

                default:
                    field = "score";
                    break;
                }

                nv.Add("sortField", field);
            }

            if (Query.HasValue())
            {
                nv.Add("query", Query);
            }

            return(nv);
        }
Beispiel #7
0
        public void ValidateModel(ModelStateDictionary ModelState)
        {
            if (UseBootstrap)
            {
                var r = AddressVerify.LookupAddress(Address, "", "", "", Zip);
                if (r.Line1 != "error")
                {
                    if (r.found == false)
                    {
                        ModelState.AddModelError("Zip",
                                                 r.address + ", to skip address check, Change the country to USA, Not Validated");
                    }
                    if (r.Line1 != Address)
                    {
                        Address = r.Line1;
                    }
                    if (r.City != (City ?? ""))
                    {
                        City = r.City;
                    }
                    if (r.State != (State ?? ""))
                    {
                        State = r.State;
                    }
                    if (r.Zip != (Zip ?? ""))
                    {
                        Zip = r.Zip;
                    }
                }
            }
            bool dorouting = false;
            bool doaccount = Account.HasValue() && !Account.StartsWith("X");

            if (Routing.HasValue() && !Routing.StartsWith("X"))
            {
                dorouting = true;
            }

            if (doaccount || dorouting)
            {
                if (doaccount)
                {
                    Account = Account.GetDigits();
                }
                if (dorouting)
                {
                    Routing = Routing.GetDigits();
                }
            }

            if (Type == "C")
            {
                Payments.ValidateCreditCardInfo(ModelState,
                                                new PaymentForm
                {
                    CreditCard = Cardnumber,
                    Expires    = Expires,
                    CCV        =
                        Cardcode,
                    SavePayInfo = true
                });
            }
            else if (Type == "B")
            {
                Payments.ValidateBankAccountInfo(ModelState, Routing, Account);
            }
            else
            {
                ModelState.AddModelError("Type", "Must select Bank Account or Credit Card");
            }
            if (SemiEvery == "S")
            {
                if (!Day1.HasValue || !Day2.HasValue)
                {
                    ModelState.AddModelError("Day2", "Both Days must have values");
                }
                else if (Day2 > 31)
                {
                    ModelState.AddModelError("Day2", "Day2 must be 31 or less");
                }
                else if (Day1 >= Day2)
                {
                    ModelState.AddModelError("Day1", "Day1 must be less than Day2");
                }
            }
            else if (SemiEvery == "E")
            {
                if (!EveryN.HasValue || EveryN < 1)
                {
                    ModelState.AddModelError("EveryN", "Days must be > 0");
                }
            }
            else
            {
                ModelState.AddModelError("SemiEvery", "Must Choose Payment Frequency");
            }
            if (!StartWhen.HasValue)
            {
                ModelState.AddModelError("StartWhen", "StartDate must have a value");
            }
            else if (StartWhen <= DateTime.Today)
            {
                ModelState.AddModelError("StartWhen", "StartDate must occur after today");
            }
//            else if (StopWhen.HasValue && StopWhen <= StartWhen)
//                ModelState.AddModelError("StopWhen", "StopDate must occur after StartDate");

            if (!FirstName.HasValue())
            {
                ModelState.AddModelError("FirstName", "needs name");
            }
            if (!LastName.HasValue())
            {
                ModelState.AddModelError("LastName", "needs name");
            }
            if (!Address.HasValue())
            {
                ModelState.AddModelError("Address", "Needs address");
            }
            if (!UseBootstrap)
            {
                if (!City.HasValue())
                {
                    ModelState.AddModelError("City", "Needs city");
                }
                if (!State.HasValue())
                {
                    ModelState.AddModelError("State", "Needs state");
                }
            }
            if (!Zip.HasValue())
            {
                ModelState.AddModelError("Zip", "Needs zip");
            }
            if (!Phone.HasValue())
            {
                ModelState.AddModelError("Phone", "Needs phone");
            }
        }
Beispiel #8
0
        public void ValidateModel(ModelStateDictionary modelState)
        {
            var dorouting = false;
            var doaccount = Account.HasValue() && !Account.StartsWith("X");

            if (Routing.HasValue() && !Routing.StartsWith("X"))
            {
                dorouting = true;
            }

            if (doaccount || dorouting)
            {
                if (doaccount)
                {
                    Account = Account.GetDigits();
                }
                if (dorouting)
                {
                    Routing = Routing.GetDigits();
                }
            }

            if (Type == PaymentType.CreditCard)
            {
                PaymentValidator.ValidateCreditCardInfo(modelState,
                                                        new PaymentForm
                {
                    CreditCard  = CreditCard,
                    Expires     = Expires,
                    CVV         = CVV,
                    SavePayInfo = true
                });
            }
            else if (Type == PaymentType.Ach)
            {
                PaymentValidator.ValidateBankAccountInfo(modelState, Routing, Account);
            }
            else
            {
                modelState.AddModelError("Type", "Must select Bank Account or Credit Card");
            }

            if (SemiEvery == "S")
            {
                if (!Day1.HasValue || !Day2.HasValue)
                {
                    modelState.AddModelError("Day2", "Both Days must have values");
                }
                else if (Day2 > 31)
                {
                    modelState.AddModelError("Day2", "Day2 must be 31 or less");
                }
                else if (Day1 >= Day2)
                {
                    modelState.AddModelError("Day1", "Day1 must be less than Day2");
                }
            }
            else if (SemiEvery == "E")
            {
                if (!EveryN.HasValue || EveryN < 1)
                {
                    modelState.AddModelError("EveryN", "Days must be > 0");
                }
            }
            else
            {
                modelState.AddModelError("SemiEvery", "Must Choose Payment Frequency");
            }

            if (!StartWhen.HasValue)
            {
                modelState.AddModelError("StartWhen", "StartDate must have a value");
            }
            else if (StartWhen <= DateTime.Today)
            {
                modelState.AddModelError("StartWhen", "StartDate must occur after today");
            }
            //            else if (StopWhen.HasValue && StopWhen <= StartWhen)
            //                modelState.AddModelError("StopWhen", "StopDate must occur after StartDate");

            if (!FirstName.HasValue())
            {
                modelState.AddModelError("FirstName", "Needs first name");
            }
            if (!LastName.HasValue())
            {
                modelState.AddModelError("LastName", "Needs last name");
            }
            if (!Address.HasValue())
            {
                modelState.AddModelError("Address", "Needs address");
            }
            if (!City.HasValue())
            {
                modelState.AddModelError("City", "Needs city");
            }
            if (!State.HasValue())
            {
                modelState.AddModelError("State", "Needs state");
            }
            if (!Country.HasValue())
            {
                modelState.AddModelError("Country", "Needs country");
            }
            if (!Zip.HasValue())
            {
                modelState.AddModelError("Zip", "Needs zip");
            }
            if (!Phone.HasValue())
            {
                modelState.AddModelError("Phone", "Needs phone");
            }
        }
        private void ValidateBasic()
        {
            if (!FirstName.HasValue())
            {
                modelState.AddModelError(Parent.GetNameFor(mm => mm.List[Index].FirstName), "first name required");
            }

            if (!LastName.HasValue())
            {
                modelState.AddModelError(Parent.GetNameFor(mm => mm.List[Index].LastName), "last name required");
            }

            var mindate = DateTime.Parse("1/1/1753");
            var HasOneOfThreeRequired = false;

            DateTime dt;

            if (DateOfBirth.HasValue() && !Util.BirthDateValid(bmon, bday, byear, out dt))
            {
                modelState.AddModelError(Parent.GetNameFor(mm => mm.List[Index].DateOfBirth), "birthday invalid");
            }

            if (BestBirthday.HasValue && BestBirthday < mindate)
            {
                modelState.AddModelError(Parent.GetNameFor(mm => mm.List[Index].DateOfBirth), "invalid date");
            }

            if (BestBirthday.HasValue && BestBirthday > mindate)
            {
                HasOneOfThreeRequired = true;
            }

            if (Util.ValidEmail(EmailAddress))
            {
                HasOneOfThreeRequired = true;
            }

            var d = Phone.GetDigits().Length;

            if (Phone.HasValue() && d >= 10)
            {
                HasOneOfThreeRequired = true;
            }

            if (d > 20)
            {
                modelState.AddModelError(Parent.GetNameFor(mm => mm.List[Index].Phone), "too many digits in phone");
            }

            if (!HasOneOfThreeRequired)
            {
                modelState.AddModelError("FORM", "we require one of valid birthdate, email or phone to find an Existing profile");
            }

            if (!Util.ValidEmail(EmailAddress) && (person == null || !Util.ValidEmail(person.EmailAddress)))
            {
                modelState.AddModelError(Parent.GetNameFor(mm => mm.List[Index].EmailAddress), "valid email required for registration confirmation");
            }

            if (Phone.HasValue() && d < 10)
            {
                modelState.AddModelError(Parent.GetNameFor(mm => mm.List[Index].Phone), "10+ digits required");
            }
            if (!modelState.IsValid)
            {
                Log("InvalidBasic");
            }
        }
        public override async Task UpdateAsync(IRepository <Customer, Guid> repository)
        {
            var customer = await repository.GetAsync(Id);

            customer.IsNull().Throw <DataNotFoundException>(Id);

            if (Email.HasValue() && !customer.Email.Equals(Email, StringComparison.CurrentCultureIgnoreCase))
            {
                var customerSameEmail = await repository.GetFirstAsync(e => e.Email == Email);

                customerSameEmail.IsNotNull().Throw <BusinessConflictException>(string.Format(Messages.AlreadyExists, "email"));

                customer.Email = Email;
            }

            if (FirstName.HasValue())
            {
                customer.FirstName = FirstName;
            }

            if (LastName.HasValue())
            {
                customer.LastName = LastName;
            }

            if (Phone.HasValue())
            {
                customer.Phone = Phone;
            }

            if (Password.HasValue())
            {
                customer.Password = Password;
            }

            if (ShippingAddress.HasValue())
            {
                customer.ShippingAddress = ShippingAddress;
            }

            if (Country.HasValue())
            {
                customer.Country = Country;
            }

            if (State.HasValue())
            {
                customer.State = State;
            }

            if (City.HasValue())
            {
                customer.City = City;
            }

            if (Zip.HasValue())
            {
                customer.Zip = Zip;
            }

            customer.Active = Active;
            ModifiedDate    = DateTime.UtcNow;

            await repository.SaveAsync(customer);
        }