public async Task <IActionResult> DeliverPost(ListOptions options) { options = options ?? DefaultDeliverPostListOptions; var filterId = options.Filters["id"]; var filterPersonFrom = options.Filters["personFrom"]; var filterPersonTo = options.Filters["personTo"]; var vm = new DeliverPostViewModel { CurrentListOptions = options, Mail = new PaginatedList <Post>(PageSize), ReturnUrl = HttpContext.Request.PathAndQuery(), }; var destinationBranch = await _currentUserService.GetBranchAsync(); if (destinationBranch == null) { TempData.Set("message", MessageViewModel.MakeError("Setup your branch")); return(View(vm)); } var mail = await _mailDao.GetAllAsync( filterId : filterId, filterPersonFrom : filterPersonFrom, filterPersonTo : filterPersonTo, filterDestinationBranchId : destinationBranch.Id, filterState : PostState.InBranchStock, sortKey : options.SortKey, sortOrder : options.SortOrder); vm.Mail = mail.ToPaginatedList(options.Page, PageSize); return(View(vm)); }
public async Task <IActionResult> StockMail(ListOptions options) { options = options ?? DefaultListOptions; var filterPersonTo = options.Filters["personTo"]; var filterAddressTo = options.Filters["addressTo"]; var vm = new MailViewModel { Mail = new PaginatedList <Post>(PageSize), CurrentListOptions = options, ReturnUrl = HttpContext.Request.PathAndQuery() }; var branch = await _currentUserService.GetBranchAsync(); var car = await _currentUserService.GetCarAsync(); if (branch == null || car == null) { TempData.Set("message", MessageViewModel.MakeError("Setup your branch and car")); return(View(vm)); } var mail = await _mailDao.GetAllAsync( filterPersonTo : filterPersonTo, filterAddressTo : filterAddressTo, filterBranchId : branch.Id, filterState : PostState.InBranchStock, sortKey : options.SortKey, sortOrder : options.SortOrder); vm.Mail = mail.ToPaginatedList(options.Page, PageSize); 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> Index(ListOptions options) { options = options ?? DefaultStockMailListOptions; var vm = new IndexViewModel { AllBranches = await _branchesDao.GetAllAsync(), Mail = new PaginatedList <Post>(PageSize), CurrentListOptions = options, ReturnUrl = HttpContext.Request.PathAndQuery() }; if (!bool.TryParse(options.Filters["withoutAddressOnly"], out bool withoutAddresOnly)) { withoutAddresOnly = false; } NullableExtensions.TryParse(options.Filters["sourceBranchId"], out long?filterSourceBranchId); NullableExtensions.TryParse(options.Filters["destinationBranchId"], out long?filterDestinationBranchId); var filterPersonFrom = options.Filters["personFrom"]; var filterPersonTo = options.Filters["personTo"]; var filterAddressTo = options.Filters["addressTo"]; var branch = await _currentUserService.GetBranchAsync(); if (branch == null) { TempData.Set("message", MessageViewModel.MakeError("Setup your branch")); return(View(vm)); } var mail = await _mailDao.GetAllForStock( branch : branch, withoutAddressOnly : withoutAddresOnly, filterSourceBranchId : filterSourceBranchId, filterDestinationBranchId : filterDestinationBranchId, filterPersonFrom : filterPersonFrom, filterPersonTo : filterPersonTo, filterAddressTo : filterAddressTo, sortKey : options.SortKey, sortOrder : options.SortOrder); vm.Mail = mail.ToPaginatedList(options.Page, PageSize); return(View(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)); }
public async Task <IActionResult> StockMail(ListOptions options) { options = options ?? DefaultListOptions; NullableExtensions.TryParse(options.Filters["sourceBranchId"], out long?filterSourceBranchId); NullableExtensions.TryParse(options.Filters["destinationBranchId"], out long?filterDestinationBranchId); var vm = new MailViewModel { AllBranches = await _branchesDao.GetAllAsync(), Mail = new PaginatedList <Post>(PageSize), CurrentListOptions = options, ReturnUrl = HttpContext.Request.PathAndQuery() }; var branch = await _currentUserService.GetBranchAsync(); var car = await _currentUserService.GetCarAsync(); if (branch == null || car == null) { TempData.Set("message", MessageViewModel.MakeError("Setup your branch and car")); return(View(vm)); } var mail = await _mailDao.GetAllAsync( filterBranchId : branch.Id, filterSourceBranchId : filterSourceBranchId, filterDestinationBranchId : filterDestinationBranchId, filterState : PostState.InBranchStock, sortKey : options.SortKey, sortOrder : options.SortOrder); vm.Mail = mail.ToPaginatedList(options.Page, PageSize); return(View(vm)); }