Exemplo n.º 1
0
        public async Task <IActionResult> CreateGroup()
        {
            Log.Called(nameof(CreateGroup), UserInfoManager.UserId.ToString());

            if (!(UserInfoManager.UserId != Constants.NO_ID && UserInfoManager.CanUserAccessPage(UserInfoManager.UserId)))
            {
                return(RedirectToAction("AccessError", "Home"));
            }

            var dto = new CreateGroupDTO
            {
                Colors = await _colorFacade.GetColorsAsync <ColorDTO>()
            };

            return(View(dto));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ShowDetails(int unitId = Constants.NO_ID)
        {
            if (unitId == Constants.NO_ID)
            {
                return(RedirectToAction("Error", "Home"));
            }

            UnitDetailsDTO unit = await _unitFacade.GetUnitByIdAsync <UnitDetailsDTO>(unitId);

            if (!(unit != null && UserInfoManager.CanUserAccessPage(unit.OwnerId)))
            {
                return(RedirectToAction("AccessError", "Home"));
            }

            return(View(unit));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> ShowCosts(int unitId, CostSort sortBy = CostSort.Date, bool isAscending = true, int pageNumber = 1, DateTime fromDate = default, DateTime toDate = default)
        {
            var unit = await _unitFacade.GetUnitByIdAsync <UnitDTO>(unitId);

            if (!(unit != null && UserInfoManager.CanUserAccessPage(unit.OwnerId)))
            {
                return(RedirectToAction("AccessError", "Home"));
            }

            var today = DateTime.Today;

            if (fromDate == default)
            {
                fromDate = new DateTime(today.Year, today.Month, 1);
            }

            if (toDate == default)
            {
                toDate = new DateTime(today.Year, today.Month, DateTime.DaysInMonth(today.Year, today.Month));
            }

            ViewBag.UnitName    = unit.Specification.Name;
            ViewBag.SortBy      = sortBy;
            ViewBag.IsAscending = isAscending;

            var costs = await _costFacade.GetCostsByUnitIdAsync <CostDTO>(unitId, fromDate, toDate);

            SortCosts(ref costs, sortBy, isAscending);

            // TODO customizable size
            var pageSize = 10;

            var costWithUnitId = new CostsWithUnitIdDTO
            {
                CostsDTO = costs.ToPagedList(pageNumber, pageSize),
                UnitId   = unitId,
                FromDate = fromDate,
                ToDate   = toDate
            };

            return(View(costWithUnitId));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> ShowEquipments(int unitId)
        {
            var unit = await _unitFacade.GetUnitByIdAsync <UnitDTO>(unitId);

            if (!(unit != null && UserInfoManager.CanUserAccessPage(unit.OwnerId)))
            {
                return(RedirectToAction("AccessError", "Home"));
            }

            ViewBag.UnitName = unit.Specification.Name;

            var equipments = await _equipmentFacade.GetEquipmentsByUnitIdAsync <EquipmentDTO>(unitId);

            var equipmentsWithUnitId = new EquipmentsWithUnitIdDTO
            {
                EquipmentsDTO = equipments,
                UnitId        = unitId
            };

            return(View(equipmentsWithUnitId));
        }
Exemplo n.º 5
0
        private async Task <bool> CanUserVisitPage(int unitId)
        {
            var unit = await _unitFacade.GetUnitByIdAsync <UnitDTO>(unitId);

            return(unit != null && UserInfoManager.CanUserAccessPage(unit.OwnerId));
        }
Exemplo n.º 6
0
        private async Task <bool> CanUserVisitPage(int groupId)
        {
            var group = await _unitGroupFacade.GetUnitGroupByIdAsync <UnitGroupDTO>(groupId);

            return(group != null && UserInfoManager.CanUserAccessPage(group.OwnerId));
        }