public async Task <IActionResult> ChangePassword(ChangePasswordViewModel vm) { if (!ModelState.IsValid) { return(View(vm)); } try { await _usersDao.ChangePasswordAsync( vm.UserId, vm.CurrentPassword, vm.NewPassword); } catch (IdentityException e) { foreach (var error in e.Errors) { ModelState.AddModelError("", error); } } catch (Exception e) { ModelState.AddModelError("", e.Message); } TempData.Set("message", MessageViewModel.MakeInfo("Password changed")); return(View(vm)); }
public async Task <IActionResult> CreatePost(CreatePostViewModel vm) { vm.AllBranches = await _branchesDao.GetAllAsync(); if (!ModelState.IsValid) { return(View(vm)); } try { var user = await _currentUserService.GetUserAsync(); var sourceBranch = await _currentUserService.GetBranchAsync(); if (sourceBranch == null) { throw new Exception("Setup your branch"); } var post = new Post { PersonFrom = vm.PersonFrom, PersonTo = vm.PersonTo, AddressTo = vm.AddressTo, BranchId = sourceBranch.Id, SourceBranchId = sourceBranch.Id, DestinationBranchId = vm.DestinationBranchId.Value }; await _mailDao.CreateAsync(post, user); vm.PersonFrom = null; ModelState.Remove(nameof(vm.PersonFrom)); vm.PersonTo = null; ModelState.Remove(nameof(vm.PersonTo)); vm.DestinationBranchId = null; ModelState.Remove(nameof(vm.DestinationBranchId)); vm.AddressTo = null; ModelState.Remove(nameof(vm.AddressTo)); TempData.Set("message", MessageViewModel.MakeInfo($"Post #{post.Id} created")); return(View(vm)); } catch (Exception e) { ModelState.AddModelError("", e.Message); return(View(vm)); } }
public async Task <IActionResult> DeliverPost(long postId, string returnUrl) { try { var user = await _currentUserService.GetUserAsync(); await _mailDao.DeliverAsync(postId, user); TempData.Set("message", MessageViewModel.MakeInfo($"Post #{postId} delivered")); } catch (Exception e) { TempData.Set("message", MessageViewModel.MakeError(e.Message)); } return(Redirect(returnUrl)); }
public async Task <IActionResult> ResetPassword(EditViewModel vm) { try { await _usersDao.ResetPasswordAsync(vm.Id, _configration["Config:Users:DefaultPassword"]); TempData.Set("message", MessageViewModel.MakeInfo("Password reset succeded")); } catch (Exception e) { TempData.Set( "message", MessageViewModel.MakeError("Failed to reset password: " + e.Message)); } vm.AllRoles = await _rolesDao.GetAllAsync(false); return(View(nameof(Edit), vm)); }
public async Task <IActionResult> StockMail(long postId, string address, string returnUrl) { try { if (string.IsNullOrEmpty(address)) { throw new Exception("Address required"); } var user = await _currentUserService.GetUserAsync(); await _mailDao.StockAsync(postId, address, user); TempData.Set("message", MessageViewModel.MakeInfo($"Post #{postId} stocked")); } catch (Exception e) { TempData.Set("message", MessageViewModel.MakeError(e.Message)); } return(Redirect(returnUrl)); }
public async Task <IActionResult> MovePostToCar(long postId, string returnUrl) { try { var user = await _currentUserService.GetUserAsync(); var car = await _currentUserService.GetCarAsync(); if (car == null) { throw new Exception("Setup your car"); } await _mailDao.MoveToCarAsync(postId, car, true, user); TempData.Set("message", MessageViewModel.MakeInfo($"Post #{postId} moved to car")); } catch (Exception e) { TempData.Set("message", MessageViewModel.MakeError(e.Message)); } return(Redirect(returnUrl)); }
public async Task <IActionResult> MovePostToBranchStock(long postId, string returnUrl) { try { var user = await _currentUserService.GetUserAsync(); var branch = await _currentUserService.GetBranchAsync(); if (branch == null) { throw new Exception("Setup your branch"); } await _mailDao.MoveToBranchStockAsync(postId, branch, user); TempData.Set("message", MessageViewModel.MakeInfo($"Post #{postId} moved to branch stock")); } catch (Exception e) { TempData.Set("message", MessageViewModel.MakeError(e.Message)); } return(Redirect(returnUrl)); }