public async Task <IActionResult> Edit(Guid id, [Bind("CategoryId,Description,Id,Name")] Course course) { if (id != course.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(course); await _context.SaveChangesAsync(); TempData["CustomResponseAlert"] = CustomResponseAlert.GetStringResponse(ResponseStatusEnum.Success, "Saved Successfully!"); } catch (DbUpdateConcurrencyException) { if (!CourseExists(course.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(course)); }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var claim = new Claim("DefaultUserClaim", "DefaultUserAuthorization"); var addClaimResult = await _userManager.AddClaimAsync(user, claim); await _signInManager.SignInAsync(user, isPersistent : false); TempData["CustomResponseAlert"] = CustomResponseAlert.GetStringResponse(ResponseStatusEnum.Success, "Thank you for registering!"); return(RedirectToLocal(returnUrl)); } AddErrors(result); } return(View(model)); }
public async Task <IActionResult> DeleteConfirmed(string id) { var applicationUser = await _context.ApplicationUsers.SingleOrDefaultAsync(m => m.Id == id); _context.ApplicationUsers.Remove(applicationUser); await _context.SaveChangesAsync( ); TempData["CustomResponseAlert"] = CustomResponseAlert.GetStringResponse(ResponseStatusEnum.Success, "Deleted Successfully!"); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> UploadCourse(string xmlTextInput, List <IFormFile> files) { try { Course course; if (files.Count > 0) { IFormFile file = Request.Form.Files[0]; var allowedExtensions = new[] { ".xml", ".txt" }; if (!allowedExtensions.Contains(Path.GetExtension(file.FileName).ToLower( ))) { TempData["CustomResponseAlert"] = CustomResponseAlert.GetStringResponse(ResponseStatusEnum.Danger, "Only .xml and .txt files accepted"); return(View( )); } string textContent = string.Empty; using (var reader = new StreamReader(file.OpenReadStream( ))) { textContent = reader.ReadToEnd( ); } course = XmlParser.FromXml <Course>(textContent); } else { course = XmlParser.FromXml <Course>(xmlTextInput); } var courseRepository = new CourseRepository( ); await courseRepository.CreateCourse(course); TempData["CustomResponseAlert"] = CustomResponseAlert.GetStringResponse(ResponseStatusEnum.Success, "Course created successfully;"); } catch (Exception ex) { TempData["CustomResponseAlert"] = CustomResponseAlert.GetStringResponse(ResponseStatusEnum.Danger, ex.Message); } return(View( )); }
public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var result = await _signInManager .PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { return(RedirectToLocal(returnUrl)); } } TempData["CustomResponseAlert"] = CustomResponseAlert.GetStringResponse(ResponseStatusEnum.Danger, "Unable to log in!"); return(View(model)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,Email,PhoneNumber")] ApplicationUser applicationUser) { var dbUser = await _context.Users.Where(user => user.Id == id).FirstOrDefaultAsync( ); if ((dbUser == null) || (id != applicationUser.Id)) { return(NotFound( )); } if (ModelState.IsValid) { try { dbUser.ChangeEmail(applicationUser.Email); dbUser.PhoneNumber = applicationUser.PhoneNumber; _context.Update(dbUser); await _context.SaveChangesAsync( ); TempData["CustomResponseAlert"] = CustomResponseAlert.GetStringResponse(ResponseStatusEnum.Success, "Saved Successfully!"); } catch (DbUpdateConcurrencyException ex) { if (!ApplicationUserExists(applicationUser.Id)) { return(NotFound( )); } else { throw ex; } } return(RedirectToAction(nameof(Index))); } return(View(applicationUser)); }