Beispiel #1
0
        public ActionResult DepartmentCollection()
        {
            var departmentId = User.Identity.GetDepartmentId();

            var viewModel = new CollectionsViewModel()
            {
                groupedDepartmentCollections = itemDisbursementService.GetDepartmentCollection(departmentId)
            };

            return(View(viewModel));
        }
        public IHttpActionResult GetDisbursementCollectionByDepartment([FromBody] EmailViewModel viewModel)
        {
            GroupedDepartmentCollections collection = itemDisbursementService.GetDepartmentCollection(viewModel.DepartmentId).FirstOrDefault();

            if (collection == null)
            {
                var dept = departmentService.Get(viewModel.DepartmentId);
                return(Ok(new GroupedDepartmentCollections()
                {
                    CollectionPoint = dept.DepartmentCollectionPoint,
                    DepartmentName = dept.DepartmentName,
                    ItemDisbursements = null
                }));
            }

            return(Ok(collection));
        }
        public ActionResult Index()
        {
            try
            {
                var userId = User.Identity.GetUserId();

                // Retrieve delegations for user where the status is active
                var delegations = departmentDelegationService.GetAll()
                                  .Where(x => x.UserId == userId)
                                  .Where(x => x.Status == CustomStatus.isActive).ToList();

                if (delegations != null)
                {
                    foreach (var item in delegations)
                    {
                        DateRangeHelper      dateRangeHelper = new DateRangeHelper(item.StartDate, item.EndDate);
                        ApplicationDbContext context         = new ApplicationDbContext();
                        var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
                        //Check if the delegation period is now
                        bool check = dateRangeHelper.Includes(DateTime.Now);
                        if (check)
                        {
                            userManager.AddToRole(userId, "DepartmentHead");
                        }
                        else
                        {
                            userManager.RemoveFromRole(userId, "DepartmentHead");
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            if (User.IsInRole("StoreClerk") || User.IsInRole("StoreManager") || User.IsInRole("StoreSupervisor"))
            {
                var purchaseOrderCount = purchaseOrderService.GetAll().Where(po => po.Status == CustomStatus.PendingApproval).Count();
                ViewBag.Poc = purchaseOrderCount;
                var stockAdjustmentCount = stockAdjustmentService.GetAll().Where(sa => sa.Status == CustomStatus.PendingApproval).Count();
                ViewBag.Sac = stockAdjustmentCount;
                var disbursementCount = disbursementService.GetAll().Where(x => x.Status == CustomStatus.ForRetrieval).Count();
                ViewBag.D = disbursementCount;
                var itemCount = itemService.GetItemsLowerThanReorderLevel().Count();
                ViewBag.I = itemCount;

                dynamic viewModel = new ItemViewModel()
                {
                    Items = itemService.GetAll()
                };
                return(View("Index", viewModel));
            }
            if (User.IsInRole("Employee") || User.IsInRole("DepartmentHead") || User.IsInRole("Representative"))
            {
                var requisitionCount = requisitionService.GetAll()
                                       .Where(x => x.DepartmentId == User.Identity.GetDepartmentId())
                                       .Where(r => r.Status == CustomStatus.PendingApproval).Count();
                ViewBag.R = requisitionCount;

                var collectionCount = itemDisbursementService.GetDepartmentCollection(User.Identity.GetDepartmentId()).Count();
                ViewBag.C = collectionCount;

                var activeDelegationCount = departmentDelegationService.GetAll().Where(x => x.DepartmentId == User.Identity.GetDepartmentId()).Where(x => x.Status == CustomStatus.isActive).Count();
                ViewBag.adC = activeDelegationCount;

                var pendingDelegationCount = departmentDelegationService.GetAll().Where(x => x.DepartmentId == User.Identity.GetDepartmentId()).Where(x => x.Status == CustomStatus.isNotActive).Where(x => x.StartDate > DateTime.Now).Count();
                ViewBag.pdC = pendingDelegationCount;

                dynamic requistionViewModel = new RequisitionViewModel()
                {
                    Items        = itemService.GetAll(),
                    Requisitions = requisitionService.GetAll()
                                   .Where(x => x.DepartmentId == User.Identity.GetDepartmentId())
                                   .OrderByDescending(r => r.createdDateTime)
                                   .OrderByDescending(r => r.Status)
                };
                return(View("Index", requistionViewModel));
            }
            return(View());
        }