public async Task OnAddCityAsyncWithPostalCodeDown()
        {
            var postalCodeResponse = Builder <PostalCodeDto>
                                     .CreateNew()
                                     .With(p => p.HasFailed, true)
                                     .Build();

            PostalCodeService.GetCityNameByPostalCodeAsync(Arg.Any <string>()).Returns(postalCodeResponse);

            var result = await CityService.AddCityAsync("22743-011");

            result.Success.Should().BeFalse();
        }
示例#2
0
        // This method is private because only authenticated users can see this view.
        public ActionResult Index()
        {
            if (BusinessManager.Instance.GlobalManagers.FindAll().Count == 0)
            {
                ApplicationUserManager userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
                ApplicationUser        user;

                if ((user = userManager.FindByEmail("*****@*****.**")) == null)
                {
                    user = new ApplicationUser
                    {
                        Email          = "*****@*****.**",
                        FirstName      = "Ricardo",
                        LastName       = "Souza",
                        EmailConfirmed = true,
                        UserName       = "******",
                        PhoneNumber    = "(19) 99856-0989",
                        UserType       = UserType.GlobalAdmin
                    };

                    userManager.Create(user, "Ricardo12__");
                }

                string  cpf     = "000.000.000-00";
                Address address = new PostalCodeService().GetAdrressFromPostalCode("13024-420").Address;

                address.State = Common.StateTranslator.GetStateName(address.State);

                GlobalManager globalManager = new GlobalManager
                {
                    Address      = address,
                    FirstName    = user.FirstName,
                    LastName     = user.LastName,
                    CPF          = cpf,
                    Email        = user.Email,
                    Password     = user.PasswordHash,
                    Telephone    = user.PhoneNumber,
                    TokenHash    = HashServices.HashPassword("547458", cpf),
                    StreetNumber = 123
                };

                BusinessManager.Instance.GlobalManagers.Add(globalManager);
            }

            if (!Request.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            return(View());
        }
示例#3
0
        public async Task <AddCityResponseDto> AddCityAsync(string postalCode)
        {
            var regex = new Regex(@"^\d{5}-\d{3}$");

            if (!regex.IsMatch(postalCode))
            {
                return new AddCityResponseDto {
                           Success = false, Message = "Invalid postal code."
                }
            }
            ;

            var city = await CityRepository.GetByPostalCodeAsync(postalCode);

            if (city != null)
            {
                return new AddCityResponseDto {
                           Success = false, Message = "Postal code already added."
                }
            }
            ;
            var postalCodeResponse = await PostalCodeService.GetCityNameByPostalCodeAsync(postalCode);

            if (postalCodeResponse.HasFailed)
            {
                return new AddCityResponseDto {
                           Success = false, Message = "Failed on try get city name."
                }
            }
            ;

            city = new City(postalCodeResponse.CityName, postalCode);

            await CityRepository.AddAsync(city);

            return(new AddCityResponseDto
            {
                Data = new CityDto
                {
                    Key = city.Key.ToString(),
                    Name = city.Name,
                    PostalCode = city.PostalCode,
                    CreatedOn = city.CreatedOn.ToString("s")
                },
                Success = true
            });
        }
        public async Task OnAddCityAsync()
        {
            var postalCodeResponse = Builder <PostalCodeDto>
                                     .CreateNew()
                                     .With(p => p.HasFailed, false)
                                     .With(p => p.CityName, Faker.Address.City())
                                     .With(p => p.PostalCode, Faker.Address.ZipCode())
                                     .Build();

            PostalCodeService.GetCityNameByPostalCodeAsync(Arg.Any <string>()).Returns(postalCodeResponse);
            CityRepository.AddAsync(Arg.Any <City>()).Returns(Task.CompletedTask);

            var result = await CityService.AddCityAsync("22743-011");

            result.Success.Should().BeTrue();
            result.Data.Should().NotBeNull();
            result.Data.CreatedOn.Should().HaveLength(19);
        }
        public ActionResult GetAddress(string postalCode)
        {
            var address = BusinessManager.Instance.Addresses.Find(postalCode); //SPSDb.Instance.Addresses.Find();

            if (address != null)
            {
                return(Json(new JavaScriptSerializer().Serialize(address)));
            }

            var postalService = new PostalCodeService();
            var result        = postalService.GetAdrressFromPostalCode(postalCode);

            if (result.Address != null)
            {
                result.Address.State = StateTranslator.GetStateName(result.Address.State);
                BusinessManager.Instance.Addresses.Add(result.Address);
                //new AddressBO().Add(result.Address);
                return(Json(new JavaScriptSerializer().Serialize(result.Address)));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, result.Message));
        }