예제 #1
0
        public JsonResult CountNewThings()
        {
            var viewModel = new CountNewThingsViewModel();

            if (this.userService.GetById(this.User.Identity.GetUserId()).Site == null)
            {
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            var userOrg = this.userService.GetUserOrganisationId(this.User.Identity.GetUserId());

            //Get count of request for approving in item order
            if (StaticFunctions.IsHasRihgt("Approve order for item", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.ItemOrderRequestsForApproving = this.requestToAcquireItemService.GetAll()
                                                              .Where(x => !x.IsApproved)
                                                              .Where(x => !x.AreItemsGave)
                                                              .Where(x => !x.Finished)
                                                              .Where(x => x.From.Site.OrganisationId == userOrg)
                                                              .Count();
                }
                else
                {
                    viewModel.ItemOrderRequestsForApproving = this.requestToAcquireItemService.GetAll()
                                                              .Where(x => !x.IsApproved)
                                                              .Where(x => !x.AreItemsGave)
                                                              .Where(x => !x.Finished)
                                                              .Count();
                }
            }

            //Get count of approved requests in item ored
            if (StaticFunctions.IsHasRihgt("Give items for item order", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.ItemOrderApprovedRequests = this.requestToAcquireItemService.GetAll()
                                                          .Where(x => x.IsApproved)
                                                          .Where(x => !x.Finished)
                                                          .Where(x => !x.AreItemsGave)
                                                          .Where(x => x.From.Site.OrganisationId == userOrg)
                                                          .Count();
                }
                else
                {
                    viewModel.ItemOrderApprovedRequests = this.requestToAcquireItemService.GetAll()
                                                          .Where(x => x.IsApproved)
                                                          .Where(x => !x.Finished)
                                                          .Where(x => !x.AreItemsGave)
                                                          .Count();
                }
            }

            //Get count of request for finishing in item order
            if (StaticFunctions.IsHasRihgt("Create order for item", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.ItemOrderRequestsForFinishing = this.requestToAcquireItemService.GetAll()
                                                              .Where(x => x.FromId == this.User.Identity.GetUserId())
                                                              .Where(x => x.IsApproved)
                                                              .Where(x => !x.Finished)
                                                              .Where(x => x.AreItemsGave)
                                                              .Where(x => x.From.Site.OrganisationId == userOrg)
                                                              .Count();
                }
                else
                {
                    viewModel.ItemOrderRequestsForFinishing = this.requestToAcquireItemService.GetAll()
                                                              .Where(x => x.FromId == this.User.Identity.GetUserId())
                                                              .Where(x => x.IsApproved)
                                                              .Where(x => !x.Finished)
                                                              .Where(x => x.AreItemsGave)
                                                              .Count();
                }
            }

            //Get count of rquest for approving in asset order
            if (StaticFunctions.IsHasRihgt("Approve orders for asset", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.AssetOrderRequestsForApproving = this.requestForAssetService.GetAll()
                                                               .Where(x => !x.IsApproved)
                                                               .Where(x => !x.AreAssetsGave)
                                                               .Where(x => !x.Finished)
                                                               .Where(x => x.From.Site.OrganisationId == userOrg)
                                                               .Count();
                }
                else
                {
                    viewModel.AssetOrderRequestsForApproving = this.requestForAssetService.GetAll()
                                                               .Where(x => !x.IsApproved)
                                                               .Where(x => !x.AreAssetsGave)
                                                               .Where(x => !x.Finished)
                                                               .Count();
                }
            }

            //Get count of approved requests in asset order
            if (StaticFunctions.IsHasRihgt("Give assets for asset orders", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.AssetOrderApprovedRequests = this.requestForAssetService.GetAll()
                                                           .Where(x => x.IsApproved)
                                                           .Where(x => !x.Finished)
                                                           .Where(x => !x.AreAssetsGave)
                                                           .Where(x => x.From.Site.OrganisationId == userOrg)
                                                           .Count();
                }
                else
                {
                    viewModel.AssetOrderApprovedRequests = this.requestForAssetService.GetAll()
                                                           .Where(x => x.IsApproved)
                                                           .Where(x => !x.Finished)
                                                           .Where(x => !x.AreAssetsGave)
                                                           .Count();
                }
            }

            //Get count of requeet for finishing in asset order
            if (StaticFunctions.IsHasRihgt("Create order for asset", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.AssetOrderRequestsForFinishing = this.requestForAssetService.GetAll()
                                                               .Where(x => x.FromId == this.User.Identity.GetUserId())
                                                               .Where(x => x.IsApproved)
                                                               .Where(x => !x.Finished)
                                                               .Where(x => x.AreAssetsGave)
                                                               .Where(x => x.From.Site.OrganisationId == userOrg)
                                                               .Count();
                }
                else
                {
                    viewModel.AssetOrderRequestsForFinishing = this.requestForAssetService.GetAll()
                                                               .Where(x => x.FromId == this.User.Identity.GetUserId())
                                                               .Where(x => x.IsApproved)
                                                               .Where(x => !x.Finished)
                                                               .Where(x => x.AreAssetsGave)
                                                               .Count();
                }
            }

            //Get count of request for approving in provider order
            if (StaticFunctions.IsHasRihgt("Approve request to provider", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.ProviderOrderRequestsForApproving = this.requestToProviderService.GetAll()
                                                                  .Where(x => !x.IsSeenByApprover)
                                                                  .Where(x => !x.IsFinished)
                                                                  .Where(x => x.SendOffers.Count != 0)
                                                                  .Where(x => x.From.Site.OrganisationId == userOrg)
                                                                  .Count();
                }
                else
                {
                    viewModel.ProviderOrderRequestsForApproving = this.requestToProviderService.GetAll()
                                                                  .Where(x => !x.IsSeenByApprover)
                                                                  .Where(x => !x.IsFinished)
                                                                  .Where(x => x.SendOffers.Count != 0)
                                                                  .Count();
                }
            }

            //Get count of approved requests in provider order
            if (StaticFunctions.IsHasRihgt("Send request to provider", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.ProviderOrderApprovedRequests = this.requestToProviderService.GetAll()
                                                              .Where(x => x.IsSeenByApprover)
                                                              .Where(x => x.IsApproved)
                                                              .Where(x => !x.IsFinished)
                                                              .Where(x => x.FromId == this.User.Identity.GetUserId())
                                                              .Where(x => x.From.Site.OrganisationId == userOrg)
                                                              .Count();
                }
                else
                {
                    viewModel.ProviderOrderApprovedRequests = this.requestToProviderService.GetAll()
                                                              .Where(x => x.IsSeenByApprover)
                                                              .Where(x => x.IsApproved)
                                                              .Where(x => !x.IsFinished)
                                                              .Where(x => x.FromId == this.User.Identity.GetUserId())
                                                              .Count();
                }
            }

            //Get count of scrapping request for approving
            if (StaticFunctions.IsHasRihgt("Approve request for scrapping", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.ScrappingRequests = this.requestForScrappingService.GetAll()
                                                  .Where(x => !x.IsApproved)
                                                  .Where(x => !x.IsFinished)
                                                  .Where(x => x.From.Site.OrganisationId == userOrg)
                                                  .Count();
                }
                else
                {
                    viewModel.ScrappingRequests = this.requestForScrappingService.GetAll()
                                                  .Where(x => !x.IsApproved)
                                                  .Where(x => !x.IsFinished)
                                                  .Count();
                }
            }

            //Get count of relocation request for approving
            if (StaticFunctions.IsHasRihgt("Approve request for relocation", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.RelocationRequestsForApproving = this.requestForRelocationService.GetAll()
                                                               .Where(x => !x.SeenFromApprover)
                                                               .Where(x => x.From.Site.OrganisationId == userOrg)
                                                               .Where(x => !x.IsFinished)
                                                               .Count();
                }
                else
                {
                    viewModel.RelocationRequestsForApproving = this.requestForRelocationService.GetAll()
                                                               .Where(x => !x.SeenFromApprover)
                                                               .Where(x => !x.IsFinished)
                                                               .Count();
                }
            }

            //Get count of your relocation requests for issue
            //if (StaticFunctions.IsHasRihgt("Send request for relocation", User.Identity.GetUserId()))
            //{
            if (!this.IsMegaAdmin())
            {
                viewModel.RelocationsForIssue = this.requestForRelocationService.GetAll()
                                                .Where(x => !x.IsFinished)
                                                .Where(x => x.IsApproved)
                                                .Where(x => x.SeenFromApprover)
                                                .Where(x => x.PackingSlip.FromUser == null)
                                                .Where(x => x.OldUserId != null)
                                                .Where(x => x.OldUserId == this.User.Identity.GetUserId())
                                                .Count();
            }
            else
            {
                viewModel.RelocationsForIssue = this.requestForRelocationService.GetAll()
                                                .Where(x => !x.IsFinished)
                                                .Where(x => x.IsApproved)
                                                .Where(x => x.SeenFromApprover)
                                                .Where(x => x.PackingSlip.FromUser == null)
                                                .Where(x => x.OldUserId != null)
                                                .Where(x => x.OldUserId == this.User.Identity.GetUserId())
                                                .Count();
            }
            //}

            //Get count of all relocation requests for isuue
            if (StaticFunctions.IsHasRihgt("Approve request for relocation", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.RelocationForIssueAll = this.requestForRelocationService.GetAll()
                                                      .Where(x => !x.IsFinished)
                                                      .Where(x => x.IsApproved)
                                                      .Where(x => x.SeenFromApprover)
                                                      .Where(x => x.PackingSlip.FromUser == null)
                                                      .Where(x => x.From.Site.OrganisationId == userOrg)
                                                      .Where(x => x.OldUserId == null)
                                                      .Count();
                }
                else
                {
                    viewModel.RelocationForIssueAll = this.requestForRelocationService.GetAll()
                                                      .Where(x => !x.IsFinished)
                                                      .Where(x => x.IsApproved)
                                                      .Where(x => x.SeenFromApprover)
                                                      .Where(x => x.PackingSlip.FromUser == null)
                                                      .Where(x => x.From.Site.OrganisationId == userOrg)
                                                      .Where(x => x.OldUserId == null)
                                                      .Count();
                }
            }

            //Get count of your relocation requests for receive
            //if (StaticFunctions.IsHasRihgt("Send request for relocation", User.Identity.GetUserId()))
            //{
            if (!this.IsMegaAdmin())
            {
                viewModel.RelocationReceive = this.requestForRelocationService.GetAll()
                                              .Where(x => !x.IsFinished)
                                              .Where(x => x.IsApproved)
                                              .Where(x => x.SeenFromApprover)
                                              .Where(x => x.PackingSlip.FromUser != null)
                                              .Where(x => x.ToUserId != null)
                                              .Where(x => x.ToUserId == this.User.Identity.GetUserId())
                                              .Where(x => x.From.Site.OrganisationId == userOrg)
                                              .Count();
            }
            else
            {
                viewModel.RelocationReceive = this.requestForRelocationService.GetAll()
                                              .Where(x => !x.IsFinished)
                                              .Where(x => x.IsApproved)
                                              .Where(x => x.SeenFromApprover)
                                              .Where(x => x.PackingSlip.FromUser != null)
                                              .Where(x => x.ToUserId != null)
                                              .Where(x => x.ToUserId == this.User.Identity.GetUserId())
                                              .Count();
            }
            //}


            //Get count of all relocation requests for receive
            if (StaticFunctions.IsHasRihgt("Approve request for relocation", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.RelocationReceiveAll = this.requestForRelocationService.GetAll()
                                                     .Where(x => !x.IsFinished)
                                                     .Where(x => x.IsApproved)
                                                     .Where(x => x.SeenFromApprover)
                                                     .Where(x => x.PackingSlip.FromUser != null)
                                                     .Where(x => x.From.Site.OrganisationId == userOrg)
                                                     .Where(x => x.ToUserId == null)
                                                     .Count();
                }
                else
                {
                    viewModel.RelocationReceiveAll = this.requestForRelocationService.GetAll()
                                                     .Where(x => !x.IsFinished)
                                                     .Where(x => x.IsApproved)
                                                     .Where(x => x.SeenFromApprover)
                                                     .Where(x => x.PackingSlip.FromUser != null)
                                                     .Where(x => x.ToUserId == null)
                                                     .Count();
                }
            }

            //Get count of renovation requests for approving
            if (StaticFunctions.IsHasRihgt("Approve request for renovation", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.RenovationRequestsForApproving = this.requestForRenovationService.GetAll()
                                                               .Where(x => !x.IsApproved)
                                                               .Where(x => !x.IsAssetGave)
                                                               .Where(x => !x.IsAssetRenovated)
                                                               .Where(x => !x.IsFinished)
                                                               .Where(x => !x.IsSeenFromApprover)
                                                               .Where(x => x.From.Site.OrganisationId == userOrg)
                                                               .Count();
                }
                else
                {
                    viewModel.RenovationRequestsForApproving = this.requestForRenovationService.GetAll()
                                                               .Where(x => !x.IsApproved)
                                                               .Where(x => !x.IsAssetGave)
                                                               .Where(x => !x.IsAssetRenovated)
                                                               .Where(x => !x.IsFinished)
                                                               .Where(x => !x.IsSeenFromApprover)
                                                               .Count();
                }
            }

            //Get count of renovation approved requests
            if (StaticFunctions.IsHasRihgt("Send request for renovation", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.RenovationApprovedRequests = this.requestForRenovationService.GetAll()
                                                           .Where(x => !x.IsFinished)
                                                           .Where(x => x.IsSeenFromApprover)
                                                           .Where(x => x.IsApproved)
                                                           .Where(x => !x.IsAssetGave)
                                                           .Where(x => !x.IsAssetRenovated)
                                                           .Where(x => x.FromId == this.User.Identity.GetUserId())
                                                           .Where(x => x.From.Site.OrganisationId == userOrg)
                                                           .Count();
                }
                else
                {
                    viewModel.RenovationApprovedRequests = this.requestForRenovationService.GetAll()
                                                           .Where(x => !x.IsFinished)
                                                           .Where(x => x.IsSeenFromApprover)
                                                           .Where(x => x.IsApproved)
                                                           .Where(x => !x.IsAssetGave)
                                                           .Where(x => !x.IsAssetRenovated)
                                                           .Count();
                }
            }

            //Get count of asset for renovating
            if (StaticFunctions.IsHasRihgt("Renovate assets", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.RenovationAssetForRenovating = this.requestForRenovationService.GetAll()
                                                             .Where(x => !x.IsFinished)
                                                             .Where(x => x.IsSeenFromApprover)
                                                             .Where(x => x.IsApproved)
                                                             .Where(x => x.IsAssetGave)
                                                             .Where(x => !x.IsAssetRenovated)
                                                             .Where(x => !x.AssetIsReturned)
                                                             .Where(x => x.From.Site.OrganisationId == userOrg)
                                                             .Count();
                }
                else
                {
                    viewModel.RenovationAssetForRenovating = this.requestForRenovationService.GetAll()
                                                             .Where(x => !x.IsFinished)
                                                             .Where(x => x.IsSeenFromApprover)
                                                             .Where(x => x.IsApproved)
                                                             .Where(x => x.IsAssetGave)
                                                             .Where(x => !x.IsAssetRenovated)
                                                             .Where(x => !x.AssetIsReturned)
                                                             .Count();
                }
            }

            //Get count of returned assets
            if (StaticFunctions.IsHasRihgt("Send request for renovation", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.RenovationReturnedAssets = this.requestForRenovationService.GetAll()
                                                         .Where(x => !x.IsFinished)
                                                         .Where(x => x.IsSeenFromApprover)
                                                         .Where(x => x.IsAssetGave)
                                                         .Where(x => x.FromId == this.User.Identity.GetUserId())
                                                         .Where(x => x.AssetIsReturned)
                                                         .Where(x => x.From.Site.OrganisationId == userOrg)
                                                         .Count();
                }
                else
                {
                    viewModel.RenovationReturnedAssets = this.requestForRenovationService.GetAll()
                                                         .Where(x => !x.IsFinished)
                                                         .Where(x => x.IsSeenFromApprover)
                                                         .Where(x => x.IsAssetGave)
                                                         .Where(x => x.FromId == this.User.Identity.GetUserId())
                                                         .Where(x => x.AssetIsReturned)
                                                         .Count();
                }
            }

            //Get count of invoices for approving
            if (StaticFunctions.IsHasRihgt("Approve invoice", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.InvoicesForApproving = this.invoiceService.GetAll()
                                                     .Where(x => !x.IsSeenByApproved)
                                                     .Where(x => x.CompiledUser.Site.OrganisationId == userOrg)
                                                     .Count();
                }
                else
                {
                    viewModel.InvoicesForApproving = this.invoiceService.GetAll()
                                                     .Where(x => !x.IsSeenByApproved)
                                                     .Count();
                }
            }

            //Get count of invoices for paying
            if (StaticFunctions.IsHasRihgt("Pay invoice", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.InvoicesForPaid = this.invoiceService.GetAll()
                                                .Where(x => (!x.IsPaid) && (x.IsApproved))
                                                .Where(x => x.CompiledUser.Site.OrganisationId == userOrg)
                                                .Count();
                }
                else
                {
                    viewModel.InvoicesForPaid = this.invoiceService.GetAll()
                                                .Where(x => (!x.IsPaid) && (x.IsApproved))
                                                .Count();
                }
            }

            //Get count of answers from accidents
            if (!this.IsMegaAdmin())
            {
                viewModel.AccidnetsAnswers = this.accidentService.GetAll()
                                             .Where(x => x.IsAnswered)
                                             .Where(x => x.FromId == User.Identity.GetUserId())
                                             .Where(x => !x.IsSeenByUser)
                                             .Where(x => x.From.Site.OrganisationId == userOrg)
                                             .Count();
            }
            else
            {
                viewModel.AccidnetsAnswers = this.accidentService.GetAll()
                                             .Where(x => x.IsAnswered)
                                             .Where(x => x.FromId == User.Identity.GetUserId())
                                             .Where(x => !x.IsSeenByUser)
                                             .Count();
            }

            //Get count of accidents for answering
            if (StaticFunctions.IsHasRihgt("Responding to incidents", User.Identity.GetUserId()))
            {
                if (!this.IsMegaAdmin())
                {
                    viewModel.AccidentsForAnswering = this.accidentService.GetAll()
                                                      .Where(x => x.From.Site.OrganisationId == userOrg)
                                                      .Where(x => !x.IsAnswered)
                                                      .Count();
                }
                else
                {
                    viewModel.AccidentsForAnswering = this.accidentService.GetAll()
                                                      .Where(x => !x.IsAnswered)
                                                      .Count();
                }
            }
            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }