예제 #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the patient as a user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);
                    //Add a role to the new user
                    Roles.AddUserToRole(model.UserName, "patient");

                    //Create a patient object from user input

                    patient objPatient = new patient();
                    objPatient.user_name   = model.UserName;
                    objPatient.health_card = model.health_card;
                    objPatient.first_name  = model.first_name;
                    objPatient.last_name   = model.last_name;
                    objPatient.birth_date  = Convert.ToDateTime(model.bith_date);
                    objPatient.gender      = model.gender;
                    objPatient.email       = model.email;
                    objPatient.phone       = model.phone;
                    objPatient.address     = model.address;
                    objPatient.postal_code = model.postal_code;
                    objPatient.city        = model.city;
                    objPatient.province    = model.province;

                    //Insert patient into database patient table using patientClass
                    PatientClass objPat = new PatientClass();
                    objPat.commitInsert(objPatient);

                    return(RedirectToAction("Index", "Home"));
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }