コード例 #1
0
ファイル: MemberManager.cs プロジェクト: cyehia/Politiq
        public Member Add(NewMemberModel newMember)
        {
            Member member = new Member
            {
                Username = newMember.Username,
                FirstName = newMember.FirstName,
                LastName = newMember.LastName,
                Email = newMember.Email,
                LastActivity = DateTime.Now,
                Password = Crypto.HashPassword(newMember.Password)
            };

            db.Members.Add(member);
            db.SaveChanges();

            return member;
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: cyehia/Politiq
        public ActionResult Register(NewMemberModel newMember)
        {
            try
                {
                    if (ModelState.IsValid)
                    {
                        MemberManager memberManager = new MemberManager();
                        if (!memberManager.UsernameExist(newMember.Username))
                        {
                            var registeredMember = memberManager.Add(newMember);
                            FormsAuthentication.SetAuthCookie(registeredMember.Username, false);

                            return RedirectToAction("Welcome", "Home");
                        }
                        else
                        {
                            ModelState.AddModelError("", "Username already taken.");

                        }
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", e.ToString());
                }

                return View(newMember);
        }