コード例 #1
0
ファイル: GlobalAdminController.cs プロジェクト: andremn/SPS
        // 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();
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: andremn/SPS
		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);
		}