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> 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> 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)); }
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> Manage(string returnUrl) { var user = await _currentUserService.GetUserAsync(); var role = await _currentUserService.GetRoleAsync(); var vm = new ManageViewModel { UserId = user.Id, UserName = user.UserName, Email = user.Email, FirstName = user.FirstName, LastName = user.LastName, HasBranch = role.HasBranch, HasCar = role.HasCar, ReturnUrl = returnUrl }; if (vm.HasBranch) { vm.AllBranches = await _branchesDao.GetAllAsync(); var branch = await _currentUserService.GetBranchAsync(); vm.BranchId = branch?.Id ?? default(long); } if (vm.HasCar) { vm.AllCars = await _carsDao.GetAllAsync(); var car = await _currentUserService.GetCarAsync(); vm.CarId = car?.Id ?? default(long); } return(View(vm)); }
public async Task <IViewComponentResult> InvokeAsync() { var vm = new AccountViewModel { CurrentUrl = Request.PathAndQuery() }; var isLoggedIn = User.Identity.IsAuthenticated; vm.IsLoggedIn = isLoggedIn; if (!isLoggedIn) { return(View(vm)); } vm.User = await _currentUserService.GetUserAsync(); if (vm.User == null) { vm.IsLoggedIn = false; return(View(vm)); } var role = await _currentUserService.GetRoleAsync(); vm.HasBranch = role.HasBranch; vm.HasCar = role.HasCar; if (vm.HasBranch) { vm.Branch = await _currentUserService.GetBranchAsync(); } if (vm.HasCar) { vm.Car = await _currentUserService.GetCarAsync(); } return(View(vm)); }