Exemplo n.º 1
0
        public async Task <IActionResult> ManageDormitoryUsers(
            int id,
            string currentFilter,
            string searchString,
            int?page)
        {
            if (!await _authHelpers.CheckDormitoryMembership(User, id))
            {
                return(ControllerHelpers.ShowAccessDeniedErrorPage(this));
            }

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewData["CurrentFilter"] = searchString;

            var users = !string.IsNullOrEmpty(searchString)
                ? _userRepo.GetUsersWithEmailLike(searchString)
                : _userRepo.Users.ToList();

            var dormitory = _dormitoryRepo.GetSingleById(id);

            var usersWithoutDormitory = users
                                        .Where(x => x.DormitoryManagerId == null &&
                                               x.DormitoryPorterId == null &&
                                               x.RoomId == null &&
                                               x.Email != "*****@*****.**")
                                        .ToList();
            var thisDormitoryUsers = users
                                     .Where(x => x.DormitoryPorterId == dormitory.DormitoryId ||
                                            x.DormitoryManagerId == dormitory.DormitoryId ||
                                            dormitory.Rooms.Any(z => z.Id == x.RoomId))
                                     .ToList();

            users = usersWithoutDormitory.Concat(thisDormitoryUsers).ToList();

            if (dormitory == null)
            {
                return(ControllerHelpers.Show404ErrorPage(this, _localizer));
            }

            int pageSize = 10;

            return(View(new ManageDormitoryUsersViewModel(
                            new PaginatedList <ApplicationUser>(users, users.Count, page ?? 1, pageSize), dormitory)));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddLaundry(DayViewModel parentModel)
        {
            var laundry = parentModel.LaundryToAdd;

            if (!await _authHelpers.CheckDormitoryMembership(User, _dormitoryRepo.GetSingleById(laundry.DormitoryId)))
            {
                return(ControllerHelpers.ShowAccessDeniedErrorPage(this));
            }

            DayViewModel model            = null;
            var          wholeWorkingTime = laundry.startTime + laundry.shiftTime * laundry.shiftCount;

            if (wholeWorkingTime.TotalHours > 24)
            {
                model = CreateDayViewModel(laundry.DormitoryId, DateTime.Today);
                model.AddLaundryError = "Laundry's working time ends after midnight.";
            }
            else if (_laundryRepo.Laundries.Any(x => x.DormitoryId == laundry.DormitoryId && x.Position == laundry.Position))
            {
                model = CreateDayViewModel(laundry.DormitoryId, DateTime.Today);
                model.AddLaundryError = "There is a laundry with the same number.";
            }

            if (model != null)
            {
                model.LaundryToAdd = new Laundry
                {
                    startTime   = laundry.startTime,
                    shiftCount  = laundry.shiftCount,
                    shiftTime   = laundry.shiftTime,
                    Position    = laundry.Position,
                    DormitoryId = laundry.DormitoryId
                };
                return(View(nameof(Day), model));
            }

            var addedLaundry = _laundryRepo.AddLaundry(laundry.DormitoryId, laundry.Position);

            addedLaundry.startTime  = laundry.startTime;
            addedLaundry.shiftCount = laundry.shiftCount;
            addedLaundry.shiftTime  = laundry.shiftTime;

            _laundryRepo.UpdateLaundry(addedLaundry);

            return(RedirectToDayByLaundryId(addedLaundry.Id, DateTime.Now.Date));
        }
Exemplo n.º 3
0
        public async Task <bool> CheckDormitoryMembership(ClaimsPrincipal user, int dormitoryId)
        {
            var dormitory = _dormitoryRepo.GetSingleById(dormitoryId);

            return(await CheckDormitoryMembership(user, dormitory));
        }