public void Save() { context.SaveChanges(); }
//[ValidateAntiForgeryToken] //public async Task<ActionResult> Register(RegisterViewModel model) //{ // if (ModelState.IsValid) // { // var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; // var result = await UserManager.CreateAsync(user, model.Password); // if (result.Succeeded) // { // await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // // Send an email with this link // // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); // return RedirectToAction("Index", "Home"); // } // AddErrors(result); // } // // If we got this far, something failed, redisplay form // return View(model); //} public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var results = await UserManager.FindByNameAsync(model.UserName); if (results != null) { return(Json(new { success = false, errorMessage = "This User Name already exists" }, JsonRequestBehavior.AllowGet)); } else { // Create User var user = new ApplicationUser() { UserName = model.UserName, Email = model.Email, PhoneNumber = model.PhoneNumber }; var result = await UserManager.CreateAsync(user, model.Password); HanifWorkShop_DBEntity AgencyCal = new HanifWorkShop_DBEntity(); AspNetUser anu = new AspNetUser(); //AspNetUser userId = RestaurantCal.AspNetRoles.Select(a => a.Name == model.UserName).FirstOrDefault(); AspNetUser searchUser = AgencyCal.AspNetUsers.Where(a => a.UserName == model.UserName).FirstOrDefault(); decimal workShopId = SessionManger.WorkShopOfLoggedInUser(Session); if (result.Succeeded) { using (HanifWorkShop_DBEntity rc = new HanifWorkShop_DBEntity()) { try { tblWorkShopUser AgencyUser = new tblWorkShopUser(); AgencyUser.UserId = searchUser.Id; AgencyUser.workShop_id = workShopId; AgencyUser.WorkShopId = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString()); AgencyUser.CreatedBy = SessionManger.LoggedInUser(Session); AgencyUser.CreatedDateTime = DateTime.Now; AgencyUser.EditedBy = null; AgencyUser.EditedDateTime = null; // RestaurantUser.is_admin = 0; //RestaurantUser.is_loggedIn = null; //RestaurantUser.last_logged_time = null; //RestaurantUser.approve_by = null; //RestaurantUser.approve_date = null; rc.tblWorkShopUsers.Add(AgencyUser); rc.SaveChanges(); return(Json(new { success = true, successMessage = "User has created Successfully." }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, errorMessage = ex }, JsonRequestBehavior.AllowGet)); } } } else { return(Json(new { success = false, errorMessage = "This Email has already taken." }, JsonRequestBehavior.AllowGet)); } } } else { return(Json(new { success = false, errorMessage = "Model is not Valid." }, JsonRequestBehavior.AllowGet)); } }