예제 #1
0
 public ActionResult RegisterApplicant()
 {
     try
     {
         RegisterApplicantViewModel registerModel = new RegisterApplicantViewModel();
         return(View(registerModel));
     }
     catch (Exception ex)
     {
         ProcessExection("Web.AccountController.RegisterApplicant", ex, Resource.Error_RegisterApplicant);
     }
     return(View());
 }
예제 #2
0
        public ActionResult RegisterApplicant(RegisterApplicantViewModel model)
        {
            if (ModelState.ContainsKey("Register.MarnNumber"))
            {
                ModelState["Register.MarnNumber"].Errors.Clear();
            }

            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    if (WebSecurity.UserExists(model.Register.UserName))
                    {
                        this.Error(Resource.val_UserExists);
                    }
                    else
                    {
                        IBLUser bUser = new BLUser(LogError.SLogPath);
                        if (bUser.ExistEmail(model.Register.Email))
                        {
                            this.Error(string.Format(Resource.val_UserEmailExists, model.Register.Email));
                        }
                        else
                        {
                            WebSecurity.CreateUserAndAccount(model.Register.UserName, model.Register.Password);
                            model.Register.UserId = WebSecurity.GetUserId(model.Register.UserName);
                            if (model.archivo != null)
                            {
                                string serverpath = Server.MapPath("~") + ConfigurationManager.AppSettings["urlImages"].ToString();
                                model.Register.PhotoProfile = DateTime.Now.ToString("yyyyMMdd") + "_" + model.Register.UserId + "." + model.archivo.ContentType.Split('/')[1].ToString();
                                model.archivo.SaveAs(serverpath + model.Register.PhotoProfile);
                            }
                            model.Register.TypeOfUser = enumTypeOfUsers.Applicant;
                            setLocationNames(model.Register);

                            if (model.Register.CountryPassport.Value != null)
                            {
                                var place = Helper.Helper.getGlobalInformation().GetCountry(model.Register.CountryPassport.Value);
                                if (place != null)
                                {
                                    model.Register.CountryPassport.Text = place.Text;
                                }
                            }


                            bUser.SaveUser(model.Register);
                            WebSecurity.Login(model.Register.UserName, model.Register.Password);
                            IBLUser bl  = new BLUser(this.LogError.SLogPath);
                            var     usr = bl.GetUserDetails(WebSecurity.GetUserId(model.Register.UserName));
                            Helper.Helper.CurrentUser = usr;
                            return(RedirectToAction("Applicant", "DashBoard"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    ProcessExection("Web.AccountController.RegisterApplicant", ex, Resource.Error_RegisterApplicant);
                }
            }

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