public async Task <ActionResult> Create([Bind(Include = "UserTypeId,Name")] UserType userType) { if (ModelState.IsValid) { db.UserTypes.Add(userType); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(userType)); }
public async Task <ActionResult> Create(UserView view) { if (ModelState.IsValid) { var user = this.ToUser(view); db.Users.Add(user); await db.SaveChangesAsync(); UsersHelper.CreateUserASP(view.Email, "User", view.Password); return(RedirectToAction("Index")); } return(View(view)); }
public async static Task <Response> SaveChanges(LocalDatacontext db) { try { await db.SaveChangesAsync(); return(new Response { IsSuccess = true, }); } catch (Exception ex) { var response = new Response { IsSuccess = false, }; if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { response.Message = "There is a record with the same value"; } else if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("REFERENCE")) { response.Message = "The record can't be delete because it has related records"; } else { response.Message = ex.Message; } return(response); } }