public async Task<ActionResult> Register(AffiInsRegisteration model) { ObjectParameter output = new ObjectParameter("UserId", typeof(Int32)); var UserStore = new UserStore<ApplicationUser>(new ApplicationDbContext()); var UserManager = new UserManager<ApplicationUser>(UserStore); var dbuser = await UserManager.FindByNameAsync(model.UserName); var dbinst = db.Affil_Ins_Info.SingleOrDefault(m => m.Ins_Name == model.InstName); var dbinstCode = db.Affil_Ins_Info.SingleOrDefault(m => m.Inst_code == model.InstCode); if (dbinstCode != null) { TempData["Error"] = "InstituteCode Already Exists"; return RedirectToAction("Register", "AffiliationAdminSide"); } if (dbinst != null) { TempData["Error"] = "InstituteName Already Exists"; return RedirectToAction("Register", "AffiliationAdminSide"); } if (dbuser != null) { TempData["Error"] = "UserName Already Exists"; return RedirectToAction("Register", "AffiliationAdminSide"); } var User = new ApplicationUser() { UserName = model.UserName, Email = model.Email, UserType = 7, isDisable = false }; IdentityResult result = await UserManager.CreateAsync(User, model.Password); if (result.Succeeded) { await UserManager.AddToRoleAsync(User.Id, "User"); bool isgov = false; if (model.InstituteType == "Government") isgov = true; db.AJ_Affi_SinUp_User_Create(model.InstName, Convert.ToInt32(model.InstCode), Convert.ToString(model.PostalAddress), Convert.ToString(model.PTCL), Convert.ToString(model.OfficMoble), Convert.ToString(model.PrincipalName), Convert.ToString(model.PrincipalContact), isgov, Convert.ToInt32(model.DistrictId), Convert.ToInt32(model.TehsilId), Convert.ToString(model.Email), output); int instid = Convert.ToInt32(output.Value); User.Institute_ID = instid; await UserManager.UpdateAsync(User); TempData["Success"] = "User Created Successfully"; } else { var msg = ""; foreach (var error in result.Errors) { msg = msg + " " + error; } TempData["Error"] = msg; return RedirectToAction("Register", "AffiliationAdminSide"); } return RedirectToAction("Register", "AffiliationAdminSide"); }