public ActionResult ClientRegister(ClientRegister form) { ClientRegister details = new ClientRegister(); details = form; int enqID = Convert.ToInt32(TempData["EnquiryIdClient"]); //RegisterModel regMod = new RegisterModel(); //AccountController accController = new AccountController(); Enquiry enq = new Enquiry(); enq = enquiryRepository.Find(enqID); //regMod.UserName = enq.Contact.ContactEmail; string Password = PasswordGeneration(enq.Contact.ContactName, enq.Contact.MobileNumber); //regMod.Email = enq.Contact.ContactEmail; //accController.Register(regMod); MembershipCreateStatus createStatus; CodeFirstMembershipProvider provider = new CodeFirstMembershipProvider(); provider.CreateAccount(enq.Contact.ContactEmail, Password, enq.Contact.ContactEmail, out createStatus); CodeFirstRoleProvider roleProvider = new CodeFirstRoleProvider(); if (createStatus == MembershipCreateStatus.Success) { if (!roleProvider.RoleExists("Client")) { roleProvider.CreateRole("Client"); } string[] roles = { "Client" }; string[] users = {enq.Contact.ContactEmail.ToString()}; roleProvider.AddUsersToRoles(users, roles); } details.EnquiryID = Convert.ToInt32(TempData["EnquiryIdClient"]); details.ContactID = enq.ContactID; // Please see this--Pankaj clientRegisterRepository.InsertOrUpdate(details); clientRegisterRepository.Save(); return RedirectToAction("Details", new { id = details.EnquiryID }); }
public ActionResult AddEmployee(Employee employee,FormCollection col) { Employee emp = new Employee(); emp.TeamID = Convert.ToInt32(col["EmployeeTeam"]); emp.EmployeeRole = col["roles"]; emp.EmployeeContact = employee.EmployeeContact; employeeRepository.InsertOrUpdate(emp); employeeRepository.Save(); string[] roles= {emp.EmployeeRole}; string[] username = {employee.EmployeeContact.ContactEmail}; MembershipCreateStatus createStatus; CodeFirstMembershipProvider provider = new CodeFirstMembershipProvider(); provider.CreateAccount(username[0], "KStart123", employee.EmployeeContact.ContactEmail,out createStatus); CodeFirstRoleProvider roleProvider = new CodeFirstRoleProvider(); roleProvider.AddUsersToRoles(username, roles); return View(); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; CodeFirstMembershipProvider provider = new CodeFirstMembershipProvider(); provider.CreateAccount(model.UserName,model.Password,model.Email, out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return View(model); }