Ejemplo n.º 1
0
        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));
            }
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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));
        }