protected override Organization Parse()
 {
     return(new Organization
     {
         Id = ToInt(OrganizationID),
         Name = OrganizationName.ToString(),
         About = About.ToString(),
         LastUpdate = ToDateTime(LastUpdate),
         Address = CompleteAddress.ToString(),
         StreetName = StreetName.ToString(),
         StreetNumber = ToInt(StreetNo),
         Barangay = Barangay.ToString(),
         City = CityOrMunicipality.ToString(),
         State = StateOrProvince.ToString(),
         Country = Country.ToString(),
         DateEstablished = DateEstablished.ToString(),
         ParentOrganization = ParentOrganization.ToString(),
         Preacher = FeastBuilderOrPreacher.ToString(),
         Branch = BranchOrLocation.ToString(),
         ContactNumber = ContactNo.ToString(),
         Email = EmailAddress.ToString(),
         Website = Website.ToString(),
         Longitude = (float)Convert.ToDouble(Longitude),
         Latitude = (float)Convert.ToDouble(Latitude),
         RetreatSchedule = RetreatSchedule.ToString(),
         RecollectionSchedule = RecollectionSchedule.ToString(),
         TalkSchedule = TalkSchedule.ToString(),
         CampSchedule = CampSchedule.ToString(),
         VolunteerSchedule = VolunteerSchedule.ToString(),
         OrgMasking = MaskingData.ToString()
     });
 }
Exemplo n.º 2
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            // Extract the tracing service
            ITracingService tracingService = executionContext.GetExtension <ITracingService>();

            try
            {
                //Create the context
                IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
                IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
                IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

                // Don't Really Care about which entity this is
                DynamicUrlParser parser        = new DynamicUrlParser();
                EntityReference  primaryEntity = parser.ConvertToEntityReference(service, RecordUrl.Get <string>(executionContext));

                string addressLine1    = Street1.Get <string>(executionContext);
                string addressLine2    = Street2.Get <string>(executionContext);
                string city            = City.Get <string>(executionContext);
                string stateOrProvince = StateOrProvince.Get <string>(executionContext);
                string zipCode         = ZipPostalCode.Get <string>(executionContext);
                string countryName     = Country.Get <string>(executionContext);

                string rc = GenerateAddress(addressLine1, addressLine2, city, stateOrProvince, zipCode, countryName);
                FullAddress.Set(executionContext, rc);
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                throw new Exception("SBS.Workflow.SetStateChildRecords: " + ex.Message);
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Post([FromBody] StateOrProvinceForm model)
        {
            if (ModelState.IsValid)
            {
                var country = await _countryRepository.Query().FirstOrDefaultAsync(x => x.Id == model.CountryId);

                if (country == null)
                {
                    return(NotFound());
                }

                var stateProvince = new StateOrProvince
                {
                    Name      = model.Name,
                    Code      = model.Code,
                    CountryId = country.Id,
                    Country   = country,
                    Type      = model.Type
                };
                _stateOrProvinceRepository.Add(stateProvince);
                await _stateOrProvinceRepository.SaveChangesAsync();

                return(CreatedAtAction(nameof(Get), new { id = stateProvince.Id }, null));
            }
            return(BadRequest(ModelState));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name")] StateOrProvince stateOrProvince)
        {
            if (id != stateOrProvince.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _db.Update(stateOrProvince);
                    await _db.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StateOrProvinceExists(stateOrProvince.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(stateOrProvince));
        }
Exemplo n.º 5
0
        private UserAddress MakeShippingAddress()
        {
            var country = new Country()
            {
                Name = "France"
            };
            var stateOrProvince = new StateOrProvince {
                Name = "IDF", Country = country
            };


            var address = new Address
            {
                CountryId       = 1,
                AddressLine1    = "115 Rue Marcel",
                Country         = country,
                StateOrProvince = stateOrProvince,
            };

            var userAddress = new UserAddress {
                UserId = 1, Address = address
            };

            return(userAddress);
        }
Exemplo n.º 6
0
 protected override Church Parse()
 {
     return(new Church
     {
         Id = ToInt(SimbahanID),
         StreetNumber = ToInt(StreetNo),
         StreetName = StreetName.ToString(),
         Barangay = Barangay.ToString(),
         StateProvince = StateOrProvince.ToString(),
         City = City.ToString(),
         ZipCode = ZipCode.ToString(),
         CompleteAddress = CompleteAddress.ToString(),
         Diocese = Diocese.ToString(),
         Parish = Parish.ToString(),
         Priest = ParishPriest.ToString(),
         Vicariate = Vicariate.ToString(),
         DateEstablished = DateEstablished.ToString(),
         LastUpdate = ToDateTime(LastUpdate),
         FeastDay = FeastDay.ToString(),
         ContactNo = ContactNo.ToString(),
         Latitude = ToDouble(Latitude),
         Longitude = ToDouble(Longitude),
         HasAdorationChapel = ToBoolean(HasAdorationChapel),
         ChurchHistory = ChurchHistory.ToString(),
         OfficeHours = OfficeHours.ToString(),
         ChurchTypeId = ToInt(ChurchTypeID),
         Website = Website.ToString(),
         EmailAddress = EmailAddress.ToString(),
         DevotionSchedule = DevotionSchedule.ToString(),
         LocationId = ToInt(LocationID),
         ChurchCode = ChurchCode.ToString()
     });
 }
Exemplo n.º 7
0
        public async Task <Result> AddProvince(int countryId, [FromBody] ProvinceCreateParam model)
        {
            var anyCountry = _countryRepository.Query().Any(c => c.Id == countryId);

            if (!anyCountry)
            {
                throw new Exception("国家不存在");
            }
            var level = await GetLevelByParent(model.ParentId);

            var any = _provinceRepository.Query().Any(c => c.Name == model.Name && c.CountryId == countryId && c.ParentId == model.ParentId);

            if (any)
            {
                throw new Exception("单据已存在");
            }
            var province = new StateOrProvince()
            {
                CountryId    = countryId,
                ParentId     = model.ParentId,
                DisplayOrder = model.DisplayOrder,
                Name         = model.Name,
                IsPublished  = model.IsPublished,
                Level        = level,
                Code         = model.Code
            };

            _provinceRepository.Add(province);
            await _provinceRepository.SaveChangesAsync();

            await _countryService.ClearProvinceCache(countryId);

            return(Result.Ok());
        }
Exemplo n.º 8
0
        private void Gen(List <StateOrProvince> list, IList <SampleDataPcasDto> pcas, StateOrProvinceLevel level, int countryId, StateOrProvince parent = null)
        {
            int i = 0;

            foreach (var item in pcas)
            {
                var model = new StateOrProvince()
                {
                    CountryId    = countryId,
                    Parent       = parent,
                    DisplayOrder = i,
                    Name         = item.Name,
                    IsPublished  = true,
                    Level        = level,
                    Code         = item.Code
                };
                list.Add(model);

                if (item.Childrens != null && item.Childrens.Count > 0)
                {
                    Gen(list, item.Childrens, (StateOrProvinceLevel)((int)level + 1), countryId, model);
                }

                i++;
            }
        }
 public void SetDefaultCasing()
 {
     if (Line1 != null)
     {
         Line1 = Line1.ToInvariantTitleCase();
     }
     if (Line2 != null)
     {
         Line2 = Line2.ToInvariantTitleCase();
     }
     if (StateOrProvince != null)
     {
         StateOrProvince = StateOrProvince.ToInvariantTitleCase();
     }
     if (PostalCode != null)
     {
         PostalCode = PostalCode.ToUpper();
     }
     if (City != null)
     {
         City = City.ToInvariantTitleCase();
     }
     if (CountryCode != null)
     {
         CountryCode = CountryCode.ToUpper();
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Returns true if the given state has tax withholding on employee pay
        /// </summary>
        public static Boolean HasWithholding(this StateOrProvince state)
        {
            switch (state)
            {
            // Also include the unknown case, we won't flag them for withholding
            case StateOrProvince.Unknown:

            // TODO These provinces have their own tax systems, and may or may not have province-specific withholding

            case StateOrProvince.GU:
            case StateOrProvince.PR:
            case StateOrProvince.VI:
            case StateOrProvince.AS:
            case StateOrProvince.MP:

            // States that don't have income withholding

            case StateOrProvince.FL:
            case StateOrProvince.AK:
            case StateOrProvince.NV:
            case StateOrProvince.NH:
            case StateOrProvince.SD:
            case StateOrProvince.TN:
            case StateOrProvince.TX:
            case StateOrProvince.WY:
                return(false);

            default:
                return(true);
            }
        }
        private UserAddress MakeShippingAddress()
        {
            var country = new Country("FR")
            {
                Name = "France"
            };
            var stateOrProvince = new StateOrProvince {
                Name = "IDF", Country = country, Type = "State"
            };
            var district = new District {
                Location = "Center", StateOrProvince = stateOrProvince, Name = "Paris"
            };

            var address = new Address
            {
                CountryId       = "FR",
                AddressLine1    = "115 Rue Marcel",
                Country         = country,
                StateOrProvince = stateOrProvince,
                District        = district
            };

            var userAddress = new UserAddress {
                UserId = 1, Address = address, AddressType = AddressType.Shipping
            };

            return(userAddress);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Find the tax table header for the given state and year
 /// </summary>
 public static TaxTableHeader GetForState(StateOrProvince state, int year)
 {
     return
         (Tables
          .Where(table => table.Year == year)
          .SelectMany(table => table.Entries)
          .Where(entry => entry.State == state)
          .Single());
 }
Exemplo n.º 13
0
        public IActionResult GetStateOrProvince([FromBody] StateOrProvince vm)
        {
            var stateOrProvinces = _stateOrProvinceRepository
                                   .Query().Where(x => x.CountryId == vm.CountryId)
                                   .Select(x => new { Id = x.Id, Name = x.Name })
                                   .ToList();

            return(Ok(stateOrProvinces));
        }
Exemplo n.º 14
0
 /// <summary>
 /// Find the tax table implementation for the given state and year
 /// </summary>
 public static T GetForState <T>(StateOrProvince state, int year) where T : TaxTableHeader
 {
     return
         (Tables
          .Where(table => table.Year == year)
          .SelectMany(table => table.Entries)
          .Where(entry => entry.State == state)
          .OfType <T>()
          .SingleOrDefault());
 }
        public async Task <IActionResult> Create([Bind("ID,Name")] StateOrProvince stateOrProvince)
        {
            if (ModelState.IsValid)
            {
                _db.Add(stateOrProvince);
                await _db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(stateOrProvince));
        }
Exemplo n.º 16
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = City.GetHashCode();
         hashCode = (hashCode * 397) ^ Street.GetHashCode();
         hashCode = (hashCode * 397) ^ StateOrProvince.GetHashCode();
         hashCode = (hashCode * 397) ^ Country.GetHashCode();
         return(hashCode);
     }
 }
Exemplo n.º 17
0
        /// <summary>
        /// Returns true if the given state has an employee deduction requirement for Unemployment Insurance
        /// </summary>
        public static Boolean HasUnemploymentEmployeeDeduction(this StateOrProvince state)
        {
            switch (state)
            {
            case StateOrProvince.AK:
            case StateOrProvince.NJ:
            case StateOrProvince.PA:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (City != null)
         {
             hashCode = hashCode * 59 + City.GetHashCode();
         }
         if (Country != null)
         {
             hashCode = hashCode * 59 + Country.GetHashCode();
         }
         if (EmailAddress != null)
         {
             hashCode = hashCode * 59 + EmailAddress.GetHashCode();
         }
         if (FaxNumber != null)
         {
             hashCode = hashCode * 59 + FaxNumber.GetHashCode();
         }
         if (PhoneNumber != null)
         {
             hashCode = hashCode * 59 + PhoneNumber.GetHashCode();
         }
         if (PostCode != null)
         {
             hashCode = hashCode * 59 + PostCode.GetHashCode();
         }
         if (StateOrProvince != null)
         {
             hashCode = hashCode * 59 + StateOrProvince.GetHashCode();
         }
         if (Street1 != null)
         {
             hashCode = hashCode * 59 + Street1.GetHashCode();
         }
         if (Street2 != null)
         {
             hashCode = hashCode * 59 + Street2.GetHashCode();
         }
         if (MediumCharacteristicType != null)
         {
             hashCode = hashCode * 59 + MediumCharacteristicType.GetHashCode();
         }
         return(hashCode);
     }
 }
Exemplo n.º 19
0
        /// <summary>
        /// Returns true if the given state has a statutory disability plan program obligation
        /// </summary>
        public static Boolean HasStatutoryDisabilityPlan(this StateOrProvince state)
        {
            switch (state)
            {
            case StateOrProvince.NY:
            case StateOrProvince.NJ:
            case StateOrProvince.RI:
            case StateOrProvince.CA:
            case StateOrProvince.HI:
            case StateOrProvince.PR:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Find the tax table header for the given state and year
        /// </summary>
        public static TaxTableHeader GetForState(StateOrProvince state, int year)
        {
            var header =
                Tables
                .Where(table => table.Year == year)
                .SelectMany(table => table.Entries)
                .Where(entry => entry.State == state)
                .SingleOrDefault();

            if (header == null)
            {
                throw new ArgumentOutOfRangeException($"{state.DisplayName()} is not supported for year {year}");
            }

            return(header);
        }
        public async Task DefaultAddressViewComponent_Should_Returns_DefaultAddress()
        {
            // Arrange
            var mockRepository = new Mock <IRepository <Address> >();
            var country        = new Country {
                Name = "France"
            };
            var stateOrProvince = new StateOrProvince {
                Name = "IDF", Country = country, Type = "State"
            };
            var district = new District {
                Location = "Center", StateOrProvince = stateOrProvince, Name = "Paris"
            };

            var address = new Address
            {
                CountryId       = 1,
                AddressLine1    = "115 Rue Marcel",
                Country         = country,
                StateOrProvince = stateOrProvince,
                District        = district
            };

            mockRepository.Setup(x => x.Query()).Returns(new List <Address> {
                address
            }.AsQueryable());
            var mockWorkContext = new Mock <IWorkContext>();
            var user            = new User {
                Id = 1, FullName = "Maher", DefaultShippingAddressId = 0
            };

            mockWorkContext.Setup(x => x.GetCurrentUser()).Returns(Task.FromResult(user));
            var component = new DefaultAddressViewComponent(mockRepository.Object, mockWorkContext.Object);

            // Act
            var result = await component.InvokeAsync();

            // Assert
            Assert.NotNull(result);
            var viewResult = Assert.IsType <ViewViewComponentResult>(result);

            Assert.NotNull(viewResult.ViewName);
            var model = Assert.IsType <DefaultAddressViewComponentVm>(viewResult.ViewData.Model);

            Assert.Equal(address.AddressLine1, model.Address.AddressLine1);
            Assert.Equal("/Modules/SimplCommerce.Module.Core/Views/Components/DefaultAddress.cshtml", viewResult.ViewName);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Add city to country
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel <Guid> > AddCityToCountryAsync(AddCityViewModel model)
        {
            if (model == null)
            {
                return(new InvalidParametersResultModel <Guid>());
            }
            var id        = Guid.NewGuid();
            var dataModel = new StateOrProvince(id)
            {
                Name      = model.Name,
                Code      = model.Code,
                CountryId = model.CountryId,
                Type      = model.Type
            };
            await _context.StateOrProvinces.AddAsync(dataModel);

            var dbRequest = await _context.PushAsync();

            return(dbRequest.Map(dataModel.Id));
        }
Exemplo n.º 23
0
        /// <summary>
        /// Update city
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel> UpdateCityAsync(StateOrProvince model)
        {
            if (model == null)
            {
                return(new InvalidParametersResultModel());
            }
            var city = await _context.StateOrProvinces
                       .AsNoTracking()
                       .FirstOrDefaultAsync(x => x.Id.Equals(model.Id));

            if (city == null)
            {
                return(new NotFoundResultModel());
            }
            city.Name      = model.Name;
            city.CountryId = model.CountryId;
            city.Type      = model.Type;
            _context.StateOrProvinces.Update(city);
            return(await _context.PushAsync());
        }
Exemplo n.º 24
0
        /// <summary>
        /// Returns true if the given state has tax withholding on employee pay
        /// </summary>
        public static Boolean HasWithholding(this StateOrProvince state)
        {
            switch (state)
            {
            // Also include the unknown case, we won't flag them for withholding
            case StateOrProvince.Unknown:

            case StateOrProvince.FL:
            case StateOrProvince.AK:
            case StateOrProvince.NV:
            case StateOrProvince.NH:
            case StateOrProvince.SD:
            case StateOrProvince.TN:
            case StateOrProvince.TX:
            case StateOrProvince.WY:
                return(false);

            default:
                return(true);
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// U.S. territories are islands under the jurisdiction of the United States which are not States of the United States.
        /// Those that have their own governments and their own tax systems (Puerto Rico, U.S. Virgin Islands, Guam, American Samoa, and The Commonwealth of the Northern Mariana Islands)
        /// and are not subject to the income taxes and withholding of U.S. federal income taxes.
        /// </summary>
        public static Boolean HasFederalWithholding(this StateOrProvince state)
        {
            switch (state)
            {
            // Have their own gov't and tax systems, do not fall under the Federal income taxes

            case StateOrProvince.GU:
            case StateOrProvince.PR:
            case StateOrProvince.VI:
            case StateOrProvince.AS:
            case StateOrProvince.MP:

            // Also include the unknown case, we won't flag them for withholding

            case StateOrProvince.Unknown:

                return(false);

            default:
                return(true);
            }
        }
Exemplo n.º 26
0
        private Address MakeAddress()
        {
            var country = new Country {
                Name = "France"
            };
            var stateOrProvince = new StateOrProvince {
                Name = "IDF", Country = country, Type = "State"
            };
            var district = new District {
                Location = "Center", StateOrProvince = stateOrProvince, Name = "Paris"
            };

            var address = new Address
            {
                CountryId       = 1,
                AddressLine1    = "115 Rue Marcel",
                Country         = country,
                StateOrProvince = stateOrProvince,
                District        = district
            };

            return(address);
        }
        public static IEnumerable <String> ForState(StateOrProvince state)
        {
            if (state.HasWithholding())
            {
                switch (state)
                {
                // TODO Louisiana, Mississippi, Missouri

                case StateOrProvince.KS:
                    yield return(Kansas.FilingStatus.Single.ToString());

                    yield return(Kansas.FilingStatus.MarriedOrHoH.ToString());

                    break;

                case StateOrProvince.NJ:
                    yield return(NewJersey.FilingStatus.Single.ToString());

                    yield return(NewJersey.FilingStatus.MarriedWithTwoIncomes.ToString());

                    yield return(NewJersey.FilingStatus.MarriedWithOneIncome.ToString());

                    yield return(NewJersey.FilingStatus.MarriedFilingSeparate.ToString());

                    yield return(NewJersey.FilingStatus.HeadOfHousehold.ToString());

                    break;

                case StateOrProvince.DE:
                    yield return(Delaware.FilingStatus.Single.ToString());

                    yield return(Delaware.FilingStatus.MarriedFilingJointly.ToString());

                    yield return(Delaware.FilingStatus.MarriedFilingSeperate.ToString());

                    break;

                case StateOrProvince.CT:
                    yield return(Connecticut.WithholdingCode.A.ToString());

                    yield return(Connecticut.WithholdingCode.B.ToString());

                    yield return(Connecticut.WithholdingCode.C.ToString());

                    yield return(Connecticut.WithholdingCode.D.ToString());

                    yield return(Connecticut.WithholdingCode.E.ToString());

                    yield return(Connecticut.WithholdingCode.F.ToString());

                    break;

                case StateOrProvince.AL:
                    yield return(Alabama.FilingStatus.Single.ToString());

                    yield return(Alabama.FilingStatus.Married.ToString());

                    yield return(Alabama.FilingStatus.MarriedFilingSeparate.ToString());

                    yield return(Alabama.FilingStatus.HeadOfFamily.ToString());

                    break;

                case StateOrProvince.OH:
                case StateOrProvince.MI:
                case StateOrProvince.KY:
                case StateOrProvince.PA:
                    yield return("Normal");

                    yield return("% of Gross");

                    break;

                case StateOrProvince.GA:
                    yield return(Georgia.FilingStatus.Single.ToString());

                    yield return(Georgia.FilingStatus.MarriedWithOneIncome.ToString());

                    yield return(Georgia.FilingStatus.MarriedWithTwoIncomes.ToString());

                    yield return(Georgia.FilingStatus.MarriedFilingSeparate.ToString());

                    yield return(Georgia.FilingStatus.HeadOfHousehold.ToString());

                    break;

                case StateOrProvince.NC:
                case StateOrProvince.CA:
                    yield return(NorthCarolina.FilingStatus.Single.ToString());

                    yield return(NorthCarolina.FilingStatus.Married.ToString());

                    yield return(NorthCarolina.FilingStatus.HeadOfHousehold.ToString());

                    break;

                case StateOrProvince.NE:
                case StateOrProvince.OK:
                case StateOrProvince.NM:
                case StateOrProvince.MD:
                case StateOrProvince.CO:
                case StateOrProvince.ND:
                case StateOrProvince.MN:
                case StateOrProvince.ME:
                case StateOrProvince.VT:
                case StateOrProvince.NY:
                case StateOrProvince.OR:
                case StateOrProvince.UT:
                case StateOrProvince.ID:
                case StateOrProvince.HI:
                case StateOrProvince.WI:
                    yield return(FilingStatus.Single.ToString());

                    yield return(FilingStatus.Married.ToString());

                    break;

                case StateOrProvince.WV:
                    yield return(WestVirginia.FilingStatus.Single_Earning.ToString());

                    yield return(WestVirginia.FilingStatus.Two_Earnings.ToString());

                    break;

                // MA: Technically, you could be both blind and head of household, but we don't have a good way to indicate that via status

                case StateOrProvince.MA:
                    yield return("Normal");

                    yield return("HeadOfHousehold");

                    yield return("Personal and/or Spouse Blindness");

                    break;

                case StateOrProvince.AZ:
                    yield return(Arizona.TaxRate.ZeroPointEightPercent.ToString());

                    yield return(Arizona.TaxRate.OnePointThreePercent.ToString());

                    yield return(Arizona.TaxRate.OnePointEightPercent.ToString());

                    yield return(Arizona.TaxRate.TwoPointSevenPercent.ToString());

                    yield return(Arizona.TaxRate.ThreePointSixPercent.ToString());

                    yield return(Arizona.TaxRate.FourPointTwoPercent.ToString());

                    yield return(Arizona.TaxRate.FivePointOnePercent.ToString());

                    break;

                default:
                    yield return("Normal");

                    break;
                }

                yield return(FilingStatus.Exempt.ToString());
            }
        }
        public static StateOrProvince[] GetData()
        {
            var stateOrProvinces = new StateOrProvince[]
            {
                new StateOrProvince {
                    Name = "Alabama"
                },
                new StateOrProvince {
                    Name = "Alaska"
                },
                new StateOrProvince {
                    Name = "Arizona"
                },
                new StateOrProvince {
                    Name = "Arkansas"
                },
                new StateOrProvince {
                    Name = "California"
                },
                new StateOrProvince {
                    Name = "Colorado"
                },
                new StateOrProvince {
                    Name = "Connecticut"
                },
                new StateOrProvince {
                    Name = "Delaware"
                },
                new StateOrProvince {
                    Name = "Florida"
                },
                new StateOrProvince {
                    Name = "Georgia"
                },
                new StateOrProvince {
                    Name = "Hawaii"
                },
                new StateOrProvince {
                    Name = "Idaho"
                },
                new StateOrProvince {
                    Name = "Illinois"
                },
                new StateOrProvince {
                    Name = "Indiana"
                },
                new StateOrProvince {
                    Name = "Iowa"
                },
                new StateOrProvince {
                    Name = "Kansas"
                },
                new StateOrProvince {
                    Name = "Kentucky"
                },
                new StateOrProvince {
                    Name = "Louisiana"
                },
                new StateOrProvince {
                    Name = "Maine"
                },
                new StateOrProvince {
                    Name = "Maryland"
                },
                new StateOrProvince {
                    Name = "Massachusetts"
                },
                new StateOrProvince {
                    Name = "Michigan"
                },
                new StateOrProvince {
                    Name = "Minnesota"
                },
                new StateOrProvince {
                    Name = "Mississippi"
                },
                new StateOrProvince {
                    Name = "Missouri"
                },
                new StateOrProvince {
                    Name = "Montana"
                },
                new StateOrProvince {
                    Name = "Nebraska"
                },
                new StateOrProvince {
                    Name = "Nevada"
                },
                new StateOrProvince {
                    Name = "New Hampshire"
                },
                new StateOrProvince {
                    Name = "New Jersey"
                },
                new StateOrProvince {
                    Name = "New Mexico"
                },
                new StateOrProvince {
                    Name = "New York"
                },
                new StateOrProvince {
                    Name = "North Carolina"
                },
                new StateOrProvince {
                    Name = "North Dakota"
                },
                new StateOrProvince {
                    Name = "Ohio"
                },
                new StateOrProvince {
                    Name = "Oklahoma"
                },
                new StateOrProvince {
                    Name = "Oregon"
                },
                new StateOrProvince {
                    Name = "Pennsylvania"
                },
                new StateOrProvince {
                    Name = "Rhode Island"
                },
                new StateOrProvince {
                    Name = "South Carolina"
                },
                new StateOrProvince {
                    Name = "South Dakota"
                },
                new StateOrProvince {
                    Name = "Tennessee"
                },
                new StateOrProvince {
                    Name = "Texas"
                },
                new StateOrProvince {
                    Name = "Utah"
                },
                new StateOrProvince {
                    Name = "Vermont"
                },
                new StateOrProvince {
                    Name = "Virginia"
                },
                new StateOrProvince {
                    Name = "Washington"
                },
                new StateOrProvince {
                    Name = "West Virginia"
                },
                new StateOrProvince {
                    Name = "Wisconsin"
                },
                new StateOrProvince {
                    Name = "Wyoming"
                },
                new StateOrProvince {
                    Name = "District of Columbia"
                },
                new StateOrProvince {
                    Name = "Ontario (CA)"
                }
            };

            return(stateOrProvinces);
        }
Exemplo n.º 29
0
 public async Task <JsonResult> UpdateCity([Required] StateOrProvince model)
 => !ModelState.IsValid ? Json(new ResultModel().AttachModelState(ModelState)) : Json(await _locationService.UpdateCityAsync(model));
Exemplo n.º 30
0
        /// <summary>
        /// Executes the workflow activity.
        /// </summary>
        /// <param name="executionContext">The execution context.</param>
        protected override void Execute(CodeActivityContext executionContext)
        {
            // Create the tracing service
            ITracingService tracingService = executionContext.GetExtension <ITracingService>();

            if (tracingService == null)
            {
                throw new InvalidPluginExecutionException("Failed to retrieve tracing service.");
            }

            tracingService.Trace("Entered " + _activityName + ".Execute(), Activity Instance Id: {0}, Workflow Instance Id: {1}",
                                 executionContext.ActivityInstanceId,
                                 executionContext.WorkflowInstanceId);

            // Create the context
            IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>();

            if (context == null)
            {
                throw new InvalidPluginExecutionException("Failed to retrieve workflow context.");
            }

            tracingService.Trace(_activityName + ".Execute(), Correlation Id: {0}, Initiating User: {1}",
                                 context.CorrelationId,
                                 context.InitiatingUserId);

            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

            try
            {
                //create a new myjsonrequest object from which data will be serialized
                JsonRequest myRequest = new JsonRequest();
                myRequest.InputObj = new CrmAzureMlDemo.Input1();
                Input input = new Input();

                string[] columns = { "address1_stateorprovince", "annualincome",            "lpa_age",
                                     "numberofchildren",         "educationcodename",       "familystatuscodename",
                                     "gendercodename",           "lpa_commutedistancename", "lpa_homeownername",
                                     "lpa_occupationname",       "lpa_numberofcarsowned",   "lpa_numberofchildrenathome" };

                object[] values = { StateOrProvince.Get(executionContext), AnnualIncome.Get(executionContext),    Age.Get(executionContext),
                                    NumChildren.Get(executionContext),     Education.Get(executionContext),       MaritalStatus.Get(executionContext),
                                    Gender.Get(executionContext),          CommuteDistance.Get(executionContext), Homeowner.Get(executionContext),
                                    Occupation.Get(executionContext),      NumCars.Get(executionContext),         NumChildrenAtHome.Get(executionContext) };

                input.Columns = columns;
                input.Values  = new object[][] { values };

                myRequest.InputObj.Inputs = new Input();
                myRequest.InputObj.Inputs = input;

                //serialize the myjsonrequest to json
                System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(myRequest.GetType());
                MemoryStream ms = new MemoryStream();
                serializer.WriteObject(ms, myRequest);
                string jsonMsg = Encoding.Default.GetString(ms.ToArray());

                //create the webrequest object and execute it (and post jsonmsg to it)
                System.Net.WebRequest req = System.Net.WebRequest.Create(Endpoint.Get(executionContext));

                //must set the content type for json
                req.ContentType = "application/json";

                //must set method to post
                req.Method = "POST";

                //add authorization header
                req.Headers.Add(string.Format("Authorization:Bearer {0}", ApiKey.Get(executionContext)));

                tracingService.Trace("json request: {0}", jsonMsg);

                //create a stream
                byte[] bytes = System.Text.Encoding.ASCII.GetBytes(jsonMsg.ToString());
                req.ContentLength = bytes.Length;
                System.IO.Stream os = req.GetRequestStream();
                os.Write(bytes, 0, bytes.Length);
                os.Close();

                //get the response
                System.Net.WebResponse resp = req.GetResponse();

                Stream responseStream = CopyAndClose(resp.GetResponseStream());
                // Do something with the stream
                StreamReader reader         = new StreamReader(responseStream, Encoding.UTF8);
                String       responseString = reader.ReadToEnd();
                tracingService.Trace("json response: {0}", responseString);

                responseStream.Position = 0;
                //deserialize the response to a myjsonresponse object
                JsonResponse myResponse = new JsonResponse();
                System.Runtime.Serialization.Json.DataContractJsonSerializer deserializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(myResponse.GetType());
                myResponse = deserializer.ReadObject(responseStream) as JsonResponse;

                //set output values from the fields of the deserialzed myjsonresponse object
                BikeBuyer.Set(executionContext, myResponse.Results.Output1.Value.Values[0][0]);
            }

            catch (WebException exception)
            {
                string str = string.Empty;
                if (exception.Response != null)
                {
                    using (StreamReader reader =
                               new StreamReader(exception.Response.GetResponseStream()))
                    {
                        str = reader.ReadToEnd();
                    }
                    exception.Response.Close();
                }
                if (exception.Status == WebExceptionStatus.Timeout)
                {
                    throw new InvalidPluginExecutionException(
                              "The timeout elapsed while attempting to issue the request.", exception);
                }
                throw new InvalidPluginExecutionException(String.Format(CultureInfo.InvariantCulture,
                                                                        "A Web exception ocurred while attempting to issue the request. {0}: {1}",
                                                                        exception.Message, str), exception);
            }
            catch (FaultException <OrganizationServiceFault> e)
            {
                tracingService.Trace("Exception: {0}", e.ToString());

                // Handle the exception.
                throw;
            }
            catch (Exception e)
            {
                tracingService.Trace("Exception: {0}", e.ToString());
                throw;
            }

            tracingService.Trace("Exiting " + _activityName + ".Execute(), Correlation Id: {0}", context.CorrelationId);
        }