コード例 #1
0
ファイル: AccountController.cs プロジェクト: shaunxu/poda
        public ActionResult Register()
        {
            var model = new AccountRegisterViewModel();
            using (var poda = Poda.Factory.Create())
            {
                var countries = poda.Execute()
                    .ForPlainSQL("SELECT * FROM Countries ORDER BY Country ASC")
                    .ReferenceOn("Countries")
                    .AsEntities<KeyValuePair<Guid, string>>(new LookupEntityConverter("ID", "Country"));
                model.Countries = new SelectList(countries, "Key", "Value");
            }

            return View(model);
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: shaunxu/poda
        public ActionResult Register(AccountRegisterViewModel model)
        {
            // server side validation
            if (ModelState.IsValid)
            {
                using (var poda = Poda.Factory.Create())
                {
                    var existingMemberCount = poda.Execute()
                        .ForPlainSQL("SELECT COUNT(ID) FROM Members WHERE Email = @Email")
                        .With("Email", model.Email)
                        .FederationOnAll()
                        .As<int>();
                    if (existingMemberCount > 0)
                    {
                        ModelState.AddModelError("Email", "This email address had been used.");
                    }
                }
            }

            if (ModelState.IsValid)
            {
                // save the new member
                using (var poda = Poda.Factory.Create())
                {
                    var memberId = Guid.NewGuid();
                    poda.Execute()
                        .ForPlainSQL("INSERT INTO Members (ID, Email, Password, CountryID) VALUES (@ID, @Email, @Password, @CountryID)")
                        .With("ID", memberId)
                        .With("Email", model.Email)
                        .With("Password", model.Password)
                        .With("CountryID", model.Country)
                        .FederationOn("Members", "ID", memberId)
                        .AsNothing();
                    poda.Commit();
                }
                // log in as this member
                var actionResult = LogOn(new AccountLogOnViewModel()
                    {
                        Email = model.Email,
                        Password = model.Password,
                        ReturnURL = string.Empty
                    });

                ShowMessage("Your account had been registered successful and logged in the system now.");
                return actionResult;
            }
            else
            {
                // display error message and back
                return Register();
            }
        }