public IActionResult Save(ProductFormViewModel viewModel) { // sample scenario: same name checking in the database if (viewModel.Title.ToLower() == "abc") { return(FormResult.CreateWarningResult("'Abc' is already exist in the database.")); } try { //... return(FormResult.CreateSuccessResult("Product saved.")); // Success form result with redirect //return FormResult.CreateSuccessResult("Product saved.", Url.Action("List", "Home")); // Success form result with redirect with delay time (15 seconds) // The message will be on the screen for 15 seconds. //return FormResult.CreateSuccessResult("Product saved.", Url.Action("List", "Home"), 15000); } catch { return(FormResult.CreateErrorResult("An error occurred!")); } // CreateSuccessResult Called this usage: //return Json(new FormResult(FormResultStatus.Success) //{ // Message = "Product saved." //}); }
public async Task <IActionResult> UpdateEducation(UpdateEducationRequestModel model) { model.UserId = User.Identity.GetUserId(); var education = await _educationService.UpdateEducationAsync(model); if (education != null) { return(FormResult.CreateSuccessResult("Updated education", Url.Action("UpdateEducation", "Education", new { Id = education.Id }))); } else { return(FormResult.CreateErrorResult("An error occurred")); } }
public IActionResult Save(Student student) { if (student.IsNew) { if (_studentList.Any(x => x.StudentNumber == student.StudentNumber)) { return(FormResult.CreateWarningResult("Aynı öğrenci numarasını kullanan başka bir öğrenci vardır.")); } _studentList.Add(student); return(FormResult.CreateSuccessResult("Öğrenci eklendi.", Url.Action("List", "Home"))); } else { var currentStudent = _studentList.Single(x => x.Id == student.Id); currentStudent = student; return(FormResult.CreateSuccessResult("Öğrenci güncellendi.", Url.Action("List", "Home"))); } }
public IActionResult Save(UserFormViewModel viewModel) { //if (!ModelState.IsValid) //{ // ViewBag.Users = _userService.GetUsers(); // return View("Index", viewModel); //} if (viewModel.FirstName == "AHMET") { return(FormResult.CreateErrorResult("Ahmet yazılamaz.")); } _userService.AddUser(new RegisteredUser { FirstName = viewModel.FirstName, LastName = viewModel.LastName }); //return RedirectToAction("Index"); return(FormResult.CreateSuccessResult("Kişi kayıt edildi, lütfen bekleyiniz", Url.Action("Index"))); }
public async Task <IActionResult> Login(LoginRequestModel model) { User user = await _userManager.FindByEmailAsync(model.Email); if (user != null) { //İlgili kullanıcıya dair önceden oluşturulmuş bir Cookie varsa siliyoruz. await _signInManager.SignOutAsync(); Microsoft.AspNetCore.Identity.SignInResult result = await _signInManager.PasswordSignInAsync(user, model.Password, model.Persistent, model.Lock); //Lock:belirli bir sürede (mesela 5 dk) kullanıcı yanlıs girerse hesabı bloklasın mı(true,false) if (result.Succeeded) { return(FormResult.CreateSuccessResult("Success", Url.Action("Index", "Home"))); } else if (result.IsNotAllowed) { return(FormResult.CreateErrorResult("Email is not activated")); } } return(FormResult.CreateErrorResult("Email or password is wrong")); }
public async Task <IActionResult> CreateAccount(LoginRequestModel model) { var user = await _userManager.FindByEmailAsync(model.Email); if (user == null || user.IsDeleted) { User newUser = new User { UserName = model.Email, Email = model.Email, FullName = model.Email, EmailConfirmed = true }; IdentityResult result = await _userManager.CreateAsync(newUser, model.Password); if (result.Succeeded) { var role = await _roleManager.FindByNameAsync(Constants.UserType.User.ToString()); if (role != null) { await _userManager.AddToRoleAsync(newUser, role.Name); } return(FormResult.CreateSuccessResult("Added user")); } else { return(FormResult.CreateErrorResult("An error occurred")); } } return(FormResult.CreateErrorResult("There is such a user")); }