public JsonResult AddNewDocAjax(AppUserDoc model) { if (string.IsNullOrEmpty(model.Id)) { #region New #region Manager var context = new ApplicationDbContext(); var userStore = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(userStore); #endregion #region Creation var appuser = new ApplicationUser { FirstName = model.FirstName, LastName = model.LastName, UserName = model.Email, Email = model.Email, Fee = model.Fee, CreationTime = DateTime.Now, LastEditDateTime = DateTime.Now, Status = true, Degree = model.Degree, Title = model.Title, Type = "Doctor", ShiftFrom = model.ShiftFrom, ShiftToo = model.ShifTo, ShiftDays = model.ShiftDays, PMDCNo = model.PMDCNo }; var result = userManager.Create(appuser, "123456"); if (result.Succeeded) { var roleAdded = userManager.AddToRole(appuser.Id, "Doctor"); var res = roleAdded.Succeeded; return(Json(new { isSuccess = true, doc = appuser, data = new List <string> { "Doctor added" } }, JsonRequestBehavior.AllowGet)); } return(Json(new { isSuccess = false, data = AddErrors(result) }, JsonRequestBehavior.AllowGet)); #endregion #endregion } #region Update var doc = DocService.UpdateDoc(model); return(Json(new { isSuccess = true, doc = doc, data = new List <string> { "Doctor updated" } }, JsonRequestBehavior.AllowGet)); #endregion }