public ActionResult RegisterAgent(RegisterAgentViewModel model) { 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.Agent; setLocationNames(model.Register); foreach (var item in model.Register.PassportHolders) { var place = Helper.Helper.getGlobalInformation().GetCountry(item.Value); if (place != null) { item.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("Agent", "DashBoard")); } } } catch (Exception ex) { ProcessExection("Web.AccountController.RegisterApplicant", ex, Resource.Error_RegisterApplicant); } } // If we got this far, something failed, redisplay form return(View(model)); }