public async Task <IActionResult> Register(UserRegisterViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } // Verify not logged in GetPrivateUserModel privateUser = await new GetAuthenticatedUserQuery().DefaultIfExceptionAsync(Mediator); if (privateUser != null && privateUser.Id > 0) { return(RedirectToAction("Login")); } // Regiser User registeredUser = await Mediator.Send(new RegisterUserCommand(viewModel.RegisterModel)); // Login var loginModel = new LoginModel { UserName = registeredUser.UserName, Password = viewModel.RegisterModel.Password }; await _userAuthService.LogInAsync(loginModel); // Attatch image if present var file = Request.Form.Files.FirstOrDefault(); if (file != null) { PostImageModel imageModel = _imageFileReader.ConvertImageFileToImageModel(file); await Mediator.Send(new AddUserImageCommand(imageModel, registeredUser.Id)); } return(RedirectToAction("Me")); }
public async Task <ActionResult> Create(BoardCreateModel boardCreateModel) { if (!ModelState.IsValid) { return(View(boardCreateModel)); } GetBoardModel addedBoard = await Mediator.Send(new AddBoardCommand(boardCreateModel.Board)); var file = Request.Form.Files.FirstOrDefault(); if (file != null) { PostImageModel imageModel = _imageFileReader.ConvertImageFileToImageModel(file); await Mediator.Send(new AddBoardImageCommand(imageModel, addedBoard.Id)); } return(RedirectToAction("Details", new { id = addedBoard.Id })); }
public async Task <ActionResult> Create(ArticleCreateViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } // Create the article GetArticleModel model = await Mediator.Send(new AddArticleCommand(viewModel.Article)); // If image attatched var file = Request.Form.Files.FirstOrDefault(); if (file != null) { PostImageModel imageModel = _imageFileReader.ConvertImageFileToImageModel(file); // Add the image to the article await Mediator.Send(new AddArticleImageCommand(imageModel, model.Id)); } return(RedirectToAction("Details", new { model.Id })); }