Exemplo n.º 1
0
        /// <summary>
        /// Gets the relevant Guid for the level of internal authorisation sent
        /// i.e. If this is a 'User' level of authorisation, then the current user AppUserId is returned.
        /// </summary>
        /// <param name="authorisationLevel"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static Guid GetAuthorisationId(InternalSearchLevelEnum authorisationLevel, IPrincipal user)
        {
            Guid id = Guid.Empty;

            AppUser         appUser  = AppUserHelpers.GetAppUser(user);
            Branch          branch   = BranchHelpers.GetBranch(appUser.CurrentBranchId);
            AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(appUser.AppUserId);

            switch (settings.OrdersDespatchedAuthorisationManageViewLevel)
            {
            case InternalSearchLevelEnum.User:
                id = appUser.AppUserId;
                break;

            case InternalSearchLevelEnum.Branch:
                id = branch.BranchId;
                break;

            case InternalSearchLevelEnum.Company:
                id = branch.CompanyId;
                break;

            case InternalSearchLevelEnum.Group:     //TO BE DONE LSLSLS
                id = appUser.AppUserId;
                break;
            }

            return(id);
        }
Exemplo n.º 2
0
        public static string GetCompanyNameTownPostCode(ApplicationDbContext db, Guid companyId)
        {
            Company company    = GetCompany(db, companyId);
            Branch  headOffice = BranchHelpers.GetBranch(db, company.HeadOfficeBranchId);

            return(headOffice.BranchName + ", " + headOffice.AddressTownCity + ", " + headOffice.AddressPostcode);
        }
Exemplo n.º 3
0
        public static AvailableListing CreateAvailableListing(ApplicationDbContext db, IPrincipal user, string itemDescription, ItemCategoryEnum itemCategory, ItemTypeEnum itemType, decimal quantityRequired, string uom, DateTime?availableFrom, DateTime?availableTo, ItemConditionEnum itemCondition, DateTime?displayUntilDate, DateTime?sellByDate, DateTime?useByDate, bool?deliveryAvailable, ItemRequiredListingStatusEnum listingStatus)
        {
            BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user);
            Branch     branch     = BranchHelpers.GetBranch(db, branchUser.BranchId);

            AvailableListing AvailableListing = new AvailableListing()
            {
                ListingId           = Guid.NewGuid(),
                ItemDescription     = itemDescription,
                ItemCategory        = itemCategory,
                ItemType            = itemType,
                QuantityRequired    = quantityRequired,
                QuantityFulfilled   = 0,
                QuantityOutstanding = quantityRequired,
                UoM                        = uom,
                AvailableFrom              = availableFrom,
                AvailableTo                = availableTo,
                ItemCondition              = itemCondition,
                DisplayUntilDate           = displayUntilDate,
                SellByDate                 = sellByDate,
                UseByDate                  = useByDate,
                DeliveryAvailable          = deliveryAvailable ?? false,
                ListingBranchPostcode      = branch.AddressPostcode,
                ListingOriginatorAppUserId = branchUser.UserId,
                ListingOriginatorBranchId  = branchUser.BranchId,
                ListingOriginatorCompanyId = branchUser.CompanyId,
                ListingOriginatorDateTime  = DateTime.Now,
                ListingStatus              = ItemRequiredListingStatusEnum.Open
            };

            db.AvailableListings.Add(AvailableListing);
            db.SaveChanges();

            return(AvailableListing);
        }
Exemplo n.º 4
0
        public static void ReassignAllTasksForUserChangingRoleFromAdmin(ApplicationDbContext db, Guid appUserId)
        {
            List <UserTaskAssignment> list = (from uta in db.UserTaskAssignments
                                              where uta.AppUserId == appUserId
                                              select uta).ToList();

            List <Guid> taskGuidsFromList = (from l in list
                                             select l.UserTaskId).Distinct().ToList();

            //Find current admins for the company
            List <AppUser> admins = AppUserHelpers.GetAdminAppUsersForCompany(db, BranchHelpers.GetBranch(db, AppUserHelpers.GetAppUser(db, appUserId).CurrentBranchId).CompanyId);

            //now match up admins to tasks and if any are missing add them
            foreach (Guid task in taskGuidsFromList)
            {
                foreach (AppUser admin in admins)
                {
                    List <Guid> assignedToTask = (from l in list
                                                  where l.UserTaskId == task
                                                  select l.AppUserId).ToList();

                    Guid result = assignedToTask.Find(x => x == admin.AppUserId);

                    if (result == Guid.Empty)
                    {
                        CopyTaskFromUserAToUserB(db, task, appUserId, admin.AppUserId);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public static RequirementListing CreateRequirementListing(ApplicationDbContext db, IPrincipal user, string itemDescription, ItemCategoryEnum itemCategory, ItemTypeEnum itemType, decimal quantityRequired, string uom, DateTime?requiredFrom, DateTime?requiredTo, bool acceptDamagedItems, bool acceptOutOfDateItems, bool collectionAvailable, ItemRequiredListingStatusEnum listingStatus, Guid?selectedCampaignId)
        {
            BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user);
            Branch     branch     = BranchHelpers.GetBranch(db, branchUser.BranchId);

            RequirementListing requirementListing = new RequirementListing()
            {
                ListingId           = Guid.NewGuid(),
                ItemDescription     = itemDescription,
                ItemCategory        = itemCategory,
                ItemType            = itemType,
                QuantityRequired    = quantityRequired,
                QuantityFulfilled   = 0,
                QuantityOutstanding = quantityRequired,
                UoM                        = uom,
                RequiredFrom               = requiredFrom,
                RequiredTo                 = requiredTo,
                AcceptDamagedItems         = acceptDamagedItems,
                AcceptOutOfDateItems       = acceptOutOfDateItems,
                CollectionAvailable        = collectionAvailable,
                ListingBranchPostcode      = branch.AddressPostcode,
                ListingOriginatorAppUserId = branchUser.UserId,
                ListingOriginatorBranchId  = branchUser.BranchId,
                ListingOriginatorCompanyId = branchUser.CompanyId,
                ListingOriginatorDateTime  = DateTime.Now,
                ListingStatus              = ItemRequiredListingStatusEnum.Open,
                CampaignId                 = selectedCampaignId
            };

            db.RequirementListings.Add(requirementListing);
            db.SaveChanges();

            return(requirementListing);
        }
Exemplo n.º 6
0
        public static List <AvailableListing> GetAllManageListingFilteredAvailableListings(ApplicationDbContext db, Guid appUserId, bool getHistory)
        {
            AppUser         appUser  = AppUserHelpers.GetAppUser(db, appUserId);
            Branch          branch   = BranchHelpers.GetBranch(db, appUser.CurrentBranchId);
            AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId);

            var dateCheck = DateTime.MinValue;

            //Create list within the time frame if setting set
            List <AvailableListing> list = new List <AvailableListing>();

            //Now bring in the Selection Level sort
            switch (settings.AvailableListingManageViewInternalSelectionLevel)
            {
            case InternalSearchLevelEnum.User:
                list = GetAllAvailableListingsForUser(db, appUserId, getHistory);
                break;

            case InternalSearchLevelEnum.Branch:     //user's current branch to filter
                list = GetAllAvailableListingsForBranch(db, branch.BranchId, getHistory);
                break;

            case InternalSearchLevelEnum.Company:     //user's current company to filter
                list = GetAllAvailableListingsForCompany(db, branch.CompanyId, getHistory);
                break;

            case InternalSearchLevelEnum.Group:     //user's built group sets to filter ***TO BE DONE***
                break;
            }

            return(list);
        }
Exemplo n.º 7
0
        public static List <Offer> GetAllManageListingFilteredOffers(ApplicationDbContext db, Guid appUserId, bool getHistory)
        {
            AppUser         appUser  = AppUserHelpers.GetAppUser(db, appUserId);
            Branch          branch   = BranchHelpers.GetBranch(db, appUser.CurrentBranchId);
            AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId);

            //Create list
            List <Offer> list = new List <Offer>();

            //Now bring in the Selection Level sort
            switch (settings.OffersManageViewInternalSelectionLevel)
            {
            case InternalSearchLevelEnum.User:
                list = GetAllOffersForUser(db, appUserId, getHistory);
                break;

            case InternalSearchLevelEnum.Branch:     //user's current branch to filter
                list = GetAllOffersForBranch(db, branch.BranchId, getHistory);
                break;

            case InternalSearchLevelEnum.Company:     //user's current company to filter
                list = GetAllOffersForCompany(db, branch.CompanyId, getHistory);
                break;

            case InternalSearchLevelEnum.Group:     //user's built group sets to filter ***TO BE DONE***
                break;
            }

            return(list);
        }
Exemplo n.º 8
0
        public static List <AvailableListing> GetAllGeneralInfoFilteredAvailableListings(ApplicationDbContext db, Guid appUserId)
        {
            AppUser         appUser  = AppUserHelpers.GetAppUser(db, appUserId);
            Branch          branch   = BranchHelpers.GetBranch(db, appUser.CurrentBranchId);
            AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId);

            var dateCheck           = DateTime.MinValue;
            int settingsMaxDistance = settings.AvailableListingGeneralInfoMaxDistance ?? 0;

            //Create list within the time frame if setting set
            List <AvailableListing> list = (from rl in db.AvailableListings
                                            where ((rl.ListingStatus == ItemRequiredListingStatusEnum.Open || rl.ListingStatus == ItemRequiredListingStatusEnum.Partial) &&
                                                   rl.ListingOriginatorDateTime >= dateCheck)
                                            orderby rl.AvailableTo ?? DateTime.MaxValue
                                            select rl).ToList();

            //Now bring in the Selection Level sort
            switch (settings.AvailableListingGeneralInfoExternalSelectionLevel)
            {
            case ExternalSearchLevelEnum.All:     //do nothing
                break;

            case ExternalSearchLevelEnum.Branch:     //user's current branch to filter
                list = list.Where(l => l.ListingOriginatorBranchId == branch.BranchId).ToList();
                break;

            case ExternalSearchLevelEnum.Company:     //user's current company to filter
                list = list.Where(l => l.ListingOriginatorCompanyId == branch.CompanyId).ToList();
                break;

            case ExternalSearchLevelEnum.Group:     //LSLSLS user's built group sets to filter ***TO BE DONE***
                break;
            }

            //Now sort by distance
            if (settingsMaxDistance > 0)
            {
                List <AvailableListing> removeList = new List <AvailableListing>();

                foreach (AvailableListing listing in list)
                {
                    DistanceHelpers distance      = new DistanceHelpers();
                    int             distanceValue = distance.GetDistance(branch.AddressPostcode, listing.ListingBranchPostcode);

                    if (distanceValue > settingsMaxDistance)
                    {
                        removeList.Add(listing);
                    }
                }

                if (removeList.Count > 0)
                {
                    list.RemoveAll(l => removeList.Contains(l));
                }
            }

            return(list);
        }
Exemplo n.º 9
0
        public static List <Campaign> GetAllGeneralInfoFilteredCampaigns(ApplicationDbContext db, Guid appUserId)
        {
            AppUser         appUser  = AppUserHelpers.GetAppUser(db, appUserId);
            Branch          branch   = BranchHelpers.GetBranch(db, appUser.CurrentBranchId);
            AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId);

            var dateCheck           = DateTime.MinValue;
            int settingsMaxDistance = settings.CampaignGeneralInfoMaxDistance ?? 0;

            //Create list within the time frame if setting set
            List <Campaign> list = (from c in db.Campaigns
                                    where (c.EntityStatus == EntityStatusEnum.Active && c.CampaignOriginatorDateTime >= dateCheck)
                                    orderby c.CampaignEndDateTime ?? DateTime.MaxValue
                                    select c).ToList();

            //Now bring in the Selection Level sort
            switch (settings.CampaignGeneralInfoExternalSelectionLevel)
            {
            case ExternalSearchLevelEnum.All:     //do nothing
                break;

            case ExternalSearchLevelEnum.Branch:     //user's current branch to filter
                list = list.Where(l => l.CampaignOriginatorBranchId == branch.BranchId).ToList();
                break;

            case ExternalSearchLevelEnum.Company:     //user's current company to filter
                list = list.Where(l => l.CampaignOriginatorCompanyId == branch.CompanyId).ToList();
                break;

            case ExternalSearchLevelEnum.Group:     //user's built group sets to filter ***TO BE DONE***
                break;
            }

            //Now sort by distance
            if (settingsMaxDistance > 0)
            {
                List <Campaign> removeList = new List <Campaign>();

                foreach (Campaign campaign in list)
                {
                    DistanceHelpers distance      = new DistanceHelpers();
                    int             distanceValue = distance.GetDistance(branch.AddressPostcode, campaign.LocationAddressPostcode);

                    if (distanceValue > settingsMaxDistance)
                    {
                        removeList.Add(campaign);
                    }
                }

                if (removeList.Count > 0)
                {
                    list.RemoveAll(l => removeList.Contains(l));
                }
            }

            return(list);
        }
Exemplo n.º 10
0
        public static OfferManageView GetOfferManageViewForOffer(ApplicationDbContext db, Offer offer, IPrincipal user)
        {
            AppUser offerAppUser = AppUserHelpers.GetAppUser(db, offer.OfferOriginatorAppUserId);

            AvailableListing   availableListing   = null;
            RequirementListing requirementListing = null;
            AppUser            listingAppUser     = null;

            switch (offer.ListingType)
            {
            case ListingTypeEnum.Available:
                availableListing = AvailableListingHelpers.GetAvailableListing(db, offer.ListingId);
                listingAppUser   = AppUserHelpers.GetAppUser(db, availableListing.ListingOriginatorAppUserId);
                break;

            case ListingTypeEnum.Requirement:
                requirementListing = RequirementListingHelpers.GetRequirementListing(db, offer.ListingId);
                listingAppUser     = AppUserHelpers.GetAppUser(db, requirementListing.ListingOriginatorAppUserId);
                break;
            }

            OfferManageView offerManageView = new OfferManageView()
            {
                OfferDetails              = offer,
                AvailableListingDetails   = availableListing,
                RequirementListingDetails = requirementListing,
                OfferAppUserDetails       = offerAppUser,
                ListingAppUserDetails     = listingAppUser,
                OfferBranchDetails        = BranchHelpers.GetBranch(db, offerAppUser.CurrentBranchId),
                ListingBranchDetails      = BranchHelpers.GetBranch(db, listingAppUser.CurrentBranchId),
                OfferAppUserSettings      = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, offerAppUser.AppUserId),
                ListingAppUserSettings    = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, listingAppUser.AppUserId)
            };

            AppUser thisAppUser = AppUserHelpers.GetAppUser(db, user);
            //If we allow branch trading then differentiate between branches for in/out trading, otherwise it is at company level
            Company thisCompany = CompanyHelpers.GetCompanyForUser(db, user);

            //set Inhouse flag
            offerManageView.InhouseOffer = OfferProcessHelpers.SetInhouseFlag(offer, thisAppUser, thisCompany);

            //set buttons
            bool?displayAcceptButton  = null;
            bool?displayRejectButton  = null;
            bool?displayCounterButton = null;
            bool?displayOfferButton   = null;

            OfferProcessHelpers.SetOrderButtons(db, user, offerManageView, out displayAcceptButton, out displayRejectButton, out displayCounterButton, out displayOfferButton);

            offerManageView.DisplayAcceptButton  = displayAcceptButton;
            offerManageView.DisplayRejectButton  = displayRejectButton;
            offerManageView.DisplayCounterButton = displayCounterButton;
            offerManageView.DisplayOfferButton   = displayOfferButton;

            return(offerManageView);
        }
Exemplo n.º 11
0
        public static Branch UpdateEntityStatus(ApplicationDbContext db, Guid branchId, EntityStatusEnum entityStatus)
        {
            Branch branch = BranchHelpers.GetBranch(db, branchId);

            branch.EntityStatus    = entityStatus;
            db.Entry(branch).State = EntityState.Modified;
            db.SaveChanges();

            return(branch);
        }
Exemplo n.º 12
0
        public static List <CampaignGeneralInfoView> GetAllCampaignsGeneralInfoView(ApplicationDbContext db, IPrincipal user)
        {
            List <CampaignGeneralInfoView> allCampaignsGeneralInfoView = new List <CampaignGeneralInfoView>();

            AppUser         appUser       = AppUserHelpers.GetAppUser(db, user);
            AppUserSettings settings      = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUser.AppUserId);
            Branch          currentBranch = BranchHelpers.GetBranch(appUser.CurrentBranchId);

            List <Campaign> allCampaigns = CampaignHelpers.GetAllGeneralInfoFilteredCampaigns(db, appUser.AppUserId);

            foreach (Campaign campaign in allCampaigns)
            {
                bool userBlocked    = false;
                bool branchBlocked  = false;
                bool companyBlocked = false;

                BlockHelpers.GetBlocksForAllTypesForSpecificOfBy(db, campaign.CampaignOriginatorAppUserId, appUser.AppUserId, campaign.CampaignOriginatorBranchId, currentBranch.BranchId, campaign.CampaignOriginatorCompanyId, currentBranch.CompanyId, out userBlocked, out branchBlocked, out companyBlocked);

                bool userMatchedOwner    = false;
                bool branchMatchedOwner  = false;
                bool companyMatchedOwner = false;

                if (currentBranch.CompanyId == campaign.CampaignOriginatorCompanyId)
                {
                    companyMatchedOwner = true;
                }
                if (currentBranch.BranchId == campaign.CampaignOriginatorBranchId)
                {
                    branchMatchedOwner = true;
                }
                if (appUser.AppUserId == campaign.CampaignOriginatorAppUserId)
                {
                    userMatchedOwner = true;
                }

                CampaignGeneralInfoView campaignGeneralInfoView = new CampaignGeneralInfoView()
                {
                    Campaign                = campaign,
                    UserLevelBlock          = userBlocked,
                    BranchLevelBlock        = branchBlocked,
                    CompanyLevelBlock       = companyBlocked,
                    DisplayBlocks           = settings.CampaignGeneralInfoDisplayBlockedListings,
                    CompanyLevelOwner       = companyMatchedOwner,
                    DisplayMyCompanyRecords = settings.CampaignGeneralInfoDisplayMyUserListings,
                    BranchLevelOwner        = branchMatchedOwner,
                    DisplayMyBranchRecords  = settings.CampaignGeneralInfoDisplayMyBranchListings,
                    UserLevelOwner          = userMatchedOwner,
                    DisplayMyRecords        = settings.CampaignGeneralInfoDisplayMyUserListings
                };

                allCampaignsGeneralInfoView.Add(campaignGeneralInfoView);
            }

            return(allCampaignsGeneralInfoView);
        }
Exemplo n.º 13
0
        public static List <Branch> GetBranchesForUser(ApplicationDbContext db, Guid appUserId)
        {
            List <BranchUser> branchUserForUser = BranchUserHelpers.GetBranchUsersForUser(db, appUserId);

            List <Branch> branchesForUser = new List <Branch>();

            foreach (BranchUser branchUser in branchUserForUser)
            {
                branchesForUser.Add(BranchHelpers.GetBranch(db, branchUser.BranchId));
            }

            List <Branch> branchesForUserDistinct = branchesForUser.Distinct().ToList();

            return(branchesForUserDistinct);
        }
Exemplo n.º 14
0
        public static List <Branch> GetBranchesForUserForAdminView(ApplicationDbContext db, Guid appUserId)
        {
            AppUser    currentAppUser    = AppUserHelpers.GetAppUser(db, appUserId);
            Branch     currentBranch     = BranchHelpers.GetBranch(db, currentAppUser.CurrentBranchId);
            BranchUser currentBranchUser = BranchUserHelpers.GetBranchUser(db, appUserId, currentAppUser.CurrentBranchId, currentBranch.CompanyId);

            List <BranchUser> branchUserForUser = BranchUserHelpers.GetBranchUsersForUserWithRole(db, appUserId, currentBranchUser.UserRole);

            List <Branch> branchesForUser = new List <Branch>();

            foreach (BranchUser branchUser in branchUserForUser)
            {
                branchesForUser.Add(BranchHelpers.GetBranch(db, branchUser.BranchId));
            }

            List <Branch> branchesForUserDistinct = branchesForUser.Distinct().ToList();

            return(branchesForUserDistinct);
        }
Exemplo n.º 15
0
        public static CampaignEditView GetCampaignEditView(ApplicationDbContext db, Guid campaignId, IPrincipal user)
        {
            Campaign campaignDetails = CampaignHelpers.GetCampaign(db, campaignId);
            AppUser  campaignAppUser = AppUserHelpers.GetAppUser(db, campaignDetails.CampaignOriginatorAppUserId);
            Branch   campaignBranch  = BranchHelpers.GetBranch(db, campaignDetails.CampaignOriginatorBranchId);
            Company  campaignCompany = CompanyHelpers.GetCompany(db, campaignDetails.CampaignOriginatorCompanyId);

            ViewButtons buttons = ViewButtonsHelpers.GetAvailableButtonsForSingleView(db, campaignAppUser, campaignBranch, campaignCompany, user);

            CampaignEditView view = new CampaignEditView()
            {
                CampaignId                 = campaignDetails.CampaignId,
                Name                       = campaignDetails.Name,
                StrapLine                  = campaignDetails.StrapLine,
                Description                = campaignDetails.Description,
                Image                      = campaignDetails.Image,
                ImageLocation              = campaignDetails.ImageLocation,
                Website                    = campaignDetails.Website,
                CampaignStartDateTime      = campaignDetails.CampaignStartDateTime,
                CampaignEndDateTime        = campaignDetails.CampaignEndDateTime,
                LocationName               = campaignDetails.LocationName,
                LocationAddressLine1       = campaignDetails.LocationAddressLine1,
                LocationAddressLine2       = campaignDetails.LocationAddressLine2,
                LocationAddressLine3       = campaignDetails.LocationAddressLine3,
                LocationAddressTownCity    = campaignDetails.LocationAddressTownCity,
                LocationAddressCounty      = campaignDetails.LocationAddressCounty,
                LocationAddressPostcode    = campaignDetails.LocationAddressPostcode,
                LocationTelephoneNumber    = campaignDetails.LocationTelephoneNumber,
                LocationEmail              = campaignDetails.LocationEmail,
                LocationContactName        = campaignDetails.LocationContactName,
                EntityStatus               = campaignDetails.EntityStatus,
                CampaignOriginatorDateTime = campaignDetails.CampaignOriginatorDateTime,
                CampaignAppUser            = campaignAppUser,
                CampaignBranchDetails      = campaignBranch,
                CampaignCompanyDetails     = campaignCompany,
                Buttons                    = buttons
            };

            return(view);
        }
Exemplo n.º 16
0
        public static List <UserTaskView> GetUserTasksForUserView(ApplicationDbContext db, Guid appUserId)
        {
            List <UserTaskView> userTasksForUserView = new List <UserTaskView>();

            List <UserTask> userTasksForUser = UserTaskHelpers.GetUserTasksForUser(db, appUserId);

            foreach (UserTask userTaskForUser in userTasksForUser)
            {
                AppUser appUser = null;
                Branch  branch  = null;

                switch (userTaskForUser.TaskType)
                {
                case TaskTypeEnum.UserOnHold:
                    appUser = AppUserHelpers.GetAppUser(db, userTaskForUser.ReferenceKey);
                    break;

                case TaskTypeEnum.BranchOnHold:
                    branch = BranchHelpers.GetBranch(db, userTaskForUser.ReferenceKey);
                    break;
                }

                UserTaskView userTaskForUserView = new UserTaskView()
                {
                    UserTaskId       = userTaskForUser.UserTaskId,
                    TaskType         = userTaskForUser.TaskType,
                    TaskDescription  = userTaskForUser.TaskDescription,
                    AppUserReference = appUser,
                    BranchReference  = branch,
                    CreatedOn        = userTaskForUser.CreatedOn,
                    CreatedBy        = AppUserHelpers.GetAppUser(db, userTaskForUser.CreatedBy),
                    EntityStatus     = userTaskForUser.EntityStatus
                };

                userTasksForUserView.Add(userTaskForUserView);
            }

            return(userTasksForUserView);
        }
Exemplo n.º 17
0
        public static AvailableListingEditView GetAvailableListingEditView(ApplicationDbContext db, Guid listingId, IPrincipal user)
        {
            AvailableListing availableListing = AvailableListingHelpers.GetAvailableListing(db, listingId);
            AppUser          listingAppUser   = AppUserHelpers.GetAppUser(db, availableListing.ListingOriginatorAppUserId);
            Branch           listingBranch    = BranchHelpers.GetBranch(db, availableListing.ListingOriginatorBranchId);
            Company          listingCompany   = CompanyHelpers.GetCompany(db, availableListing.ListingOriginatorCompanyId);

            ViewButtons buttons = ViewButtonsHelpers.GetAvailableButtonsForSingleView(db, listingAppUser, listingBranch, listingCompany, user);

            AvailableListingEditView view = new AvailableListingEditView()
            {
                ListingId           = availableListing.ListingId,
                ItemDescription     = availableListing.ItemDescription,
                ItemCategory        = availableListing.ItemCategory,
                ItemType            = availableListing.ItemType,
                QuantityRequired    = availableListing.QuantityRequired,
                QuantityFulfilled   = availableListing.QuantityFulfilled,
                QuantityOutstanding = availableListing.QuantityOutstanding,
                UoM                       = availableListing.UoM,
                AvailableFrom             = availableListing.AvailableFrom,
                AvailableTo               = availableListing.AvailableTo,
                ItemCondition             = availableListing.ItemCondition,
                DisplayUntilDate          = availableListing.DisplayUntilDate,
                SellByDate                = availableListing.SellByDate,
                UseByDate                 = availableListing.UseByDate,
                DeliveryAvailable         = availableListing.DeliveryAvailable,
                ListingStatus             = availableListing.ListingStatus,
                ListingOriginatorDateTime = availableListing.ListingOriginatorDateTime,
                ListingAppUser            = listingAppUser,
                ListingBranchDetails      = listingBranch,
                ListingCompanyDetails     = listingCompany,
                Buttons                   = buttons
            };

            return(view);
        }
Exemplo n.º 18
0
        public static List <AvailableListingGeneralInfoView> GetAllAvailableListingsGeneralInfoView(ApplicationDbContext db, IPrincipal user)
        {
            List <AvailableListingGeneralInfoView> allAvailableListingsGeneralInfoView = new List <AvailableListingGeneralInfoView>();

            AppUser         appUser       = AppUserHelpers.GetAppUser(db, user);
            AppUserSettings settings      = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUser.AppUserId);
            Branch          currentBranch = BranchHelpers.GetBranch(appUser.CurrentBranchId);

            List <AvailableListing> allAvailableListings = AvailableListingHelpers.GetAllGeneralInfoFilteredAvailableListings(db, appUser.AppUserId);

            foreach (AvailableListing availableListing in allAvailableListings)
            {
                //Find any related offers
                Offer   offer    = OfferHelpers.GetOfferForListingAndUser(db, availableListing.ListingId, appUser.AppUserId);
                decimal offerQty = 0M;
                if (offer != null)
                {
                    offerQty = offer.CurrentOfferQuantity;
                }

                bool userBlocked    = false;
                bool branchBlocked  = false;
                bool companyBlocked = false;

                BlockHelpers.GetBlocksForAllTypesForSpecificOfBy(db, availableListing.ListingOriginatorAppUserId, appUser.AppUserId, availableListing.ListingOriginatorBranchId, currentBranch.BranchId, availableListing.ListingOriginatorCompanyId, currentBranch.CompanyId, out userBlocked, out branchBlocked, out companyBlocked);

                bool userMatchedOwner    = false;
                bool branchMatchedOwner  = false;
                bool companyMatchedOwner = false;

                if (currentBranch.CompanyId == availableListing.ListingOriginatorCompanyId)
                {
                    companyMatchedOwner = true;
                }
                if (currentBranch.BranchId == availableListing.ListingOriginatorBranchId)
                {
                    branchMatchedOwner = true;
                }
                if (appUser.AppUserId == availableListing.ListingOriginatorAppUserId)
                {
                    userMatchedOwner = true;
                }

                Company company = CompanyHelpers.GetCompany(db, availableListing.ListingOriginatorCompanyId);

                AvailableListingGeneralInfoView AvailableListingGeneralInfoView = new AvailableListingGeneralInfoView()
                {
                    AvailableListing        = availableListing,
                    OfferQuantity           = offerQty,
                    AllowBranchTrading      = company.AllowBranchTrading,
                    UserLevelBlock          = userBlocked,
                    BranchLevelBlock        = branchBlocked,
                    CompanyLevelBlock       = companyBlocked,
                    DisplayBlocks           = settings.AvailableListingGeneralInfoDisplayBlockedListings,
                    CompanyLevelOwner       = companyMatchedOwner,
                    DisplayMyCompanyRecords = settings.AvailableListingGeneralInfoDisplayMyUserListings,
                    BranchLevelOwner        = branchMatchedOwner,
                    DisplayMyBranchRecords  = settings.AvailableListingGeneralInfoDisplayMyBranchListings,
                    UserLevelOwner          = userMatchedOwner,
                    DisplayMyRecords        = settings.AvailableListingGeneralInfoDisplayMyUserListings
                };

                allAvailableListingsGeneralInfoView.Add(AvailableListingGeneralInfoView);
            }

            return(allAvailableListingsGeneralInfoView);
        }
Exemplo n.º 19
0
        public static bool UpdateBranchesFromBranchAdminView(ApplicationDbContext db, List <BranchAdminView> branchesAdminView, IPrincipal user)
        {
            //Get logged in user details for Task creation (if required)
            AppUser loggedInUser = AppUserHelpers.GetAppUser(db, user);

            try
            {
                foreach (BranchAdminView branchAdminVeiw in branchesAdminView)
                {
                    //Get original branch record so that we can compare previous and current entity status'
                    Branch           branch = BranchHelpers.GetBranch(db, branchAdminVeiw.BranchId);
                    EntityStatusEnum previousEntityStatus = branch.EntityStatus;

                    //Update branch
                    branch = BranchHelpers.UpdateBranch(db,
                                                        branchAdminVeiw.BranchId,
                                                        branchAdminVeiw.CompanyId,
                                                        branchAdminVeiw.BusinessType,
                                                        branchAdminVeiw.BranchName,
                                                        branchAdminVeiw.AddressLine1,
                                                        branchAdminVeiw.AddressLine2,
                                                        branchAdminVeiw.AddressLine3,
                                                        branchAdminVeiw.AddressTownCity,
                                                        branchAdminVeiw.AddressCounty,
                                                        branchAdminVeiw.AddressPostcode,
                                                        branchAdminVeiw.TelephoneNumber,
                                                        branchAdminVeiw.Email,
                                                        branchAdminVeiw.ContactName,
                                                        branchAdminVeiw.PrivacyLevel,
                                                        branchAdminVeiw.EntityStatus);

                    //if change of status from on-hold - anything then look for outstanding task and set to closed
                    if (branchAdminVeiw.EntityStatus != EntityStatusEnum.OnHold && previousEntityStatus == EntityStatusEnum.OnHold)
                    {
                        List <UserTask> activeTasksForThisBranch = UserTaskHelpers.GetUserTasksForBranch(db, branch.BranchId);

                        foreach (UserTask activeTaskForThisBranch in activeTasksForThisBranch)
                        {
                            UserTaskHelpers.UpdateEntityStatus(activeTaskForThisBranch.UserTaskId, EntityStatusEnum.Closed);
                        }
                    }

                    //If change of status to on-hold then create a Task
                    if (branchAdminVeiw.EntityStatus == EntityStatusEnum.OnHold && previousEntityStatus != EntityStatusEnum.OnHold)
                    {
                        UserTaskHelpers.CreateUserTask(TaskTypeEnum.BranchOnHold, "New branch on hold, awaiting administrator activation", branch.BranchId, loggedInUser.AppUserId, EntityStatusEnum.Active);
                    }

                    //Update Users link with Branch
                    foreach (BranchAdminViewCompanyUser companyUser in branchAdminVeiw.RelatedCompanyUsers)
                    {
                        //Try to find the user
                        BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, companyUser.AppUserId, branchAdminVeiw.BranchId, branchAdminVeiw.CompanyId);

                        //Now check if user is checked in list then ensure it is on branchUser, else remove if it is on branchUser
                        if (companyUser.LinkedToThisBranch)
                        {
                            //if company user linked but not on BranchUser, add to BranchUser
                            if (branchUser == null)
                            {
                                BranchUserHelpers.CreateBranchUser(db, companyUser.AppUserId, branchAdminVeiw.BranchId, branchAdminVeiw.CompanyId, UserRoleEnum.User, EntityStatusEnum.Active);
                            }
                            //if company user linked but not ACTIVE on BranchUser
                            else if (branchUser.EntityStatus != EntityStatusEnum.Active)
                            {
                                BranchUserHelpers.UpdateBranchUserStatus(db, branchUser, EntityStatusEnum.Active, companyUser.AppUserId);
                            }
                        }
                        else
                        {
                            //if company user not linked but is on BranchUser, remove from BranchUser by setting status to Inactive
                            if (branchUser != null)
                            {
                                BranchUserHelpers.UpdateBranchUserStatus(db, branchUser, EntityStatusEnum.Inactive, companyUser.AppUserId);
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                return(false);
            }
        }
Exemplo n.º 20
0
        public static List <UserAdminView> GetUserAdminViewListForUser(ApplicationDbContext db, IPrincipal user)
        {
            List <UserAdminView> userAdminViewListForUser       = new List <UserAdminView>();
            List <UserAdminRelatedBranchesView> relatedBranches = new List <UserAdminRelatedBranchesView>();

            AppUser    appUser    = AppUserHelpers.GetAppUser(db, user);
            BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, appUser.AppUserId, appUser.CurrentBranchId);


            switch (user.Identity.GetCurrentUserRole())
            {
            case "SuperUser":
            case "Admin":     //Get all users for the company of this user
                var branchUsersForCompany = (from b in db.BranchUsers
                                             join a in db.AppUsers on b.UserId equals a.AppUserId
                                             where (b.CompanyId == branchUser.CompanyId && b.EntityStatus == EntityStatusEnum.Active)
                                             select new { AppUserId = b.UserId, BranchId = b.BranchId, BranchUserId = b.BranchUserId, CurrentBranchId = a.CurrentBranchId, UserRole = b.UserRole }).Distinct().ToList();

                foreach (var branchUserForCompany in branchUsersForCompany)
                {
                    UserAdminRelatedBranchesView relatedBranch = new UserAdminRelatedBranchesView();
                    relatedBranch.AppUserId    = branchUserForCompany.AppUserId;
                    relatedBranch.BranchId     = branchUserForCompany.BranchId;
                    relatedBranch.BranchUserId = branchUserForCompany.BranchUserId;
                    relatedBranch.UserRole     = branchUserForCompany.UserRole;

                    //relatedBranch.BranchUserDetails = BranchUserHelpers.GetBranchUser(db, branchUserForCompany.BranchUserId);
                    Branch branchDetails = BranchHelpers.GetBranch(db, branchUserForCompany.BranchId);

                    relatedBranch.BranchName      = branchDetails.BranchName;
                    relatedBranch.AddressLine1    = branchDetails.AddressLine1;
                    relatedBranch.AddressTownCity = branchDetails.AddressTownCity;
                    relatedBranch.AddressPostcode = branchDetails.AddressPostcode;

                    if (branchUserForCompany.BranchId == branchUserForCompany.CurrentBranchId)
                    {
                        relatedBranch.CurrentBranch = true;
                    }
                    else
                    {
                        relatedBranch.CurrentBranch = false;
                    }

                    relatedBranches.Add(relatedBranch);
                }

                List <AppUser> appUsersForCompany = (from b in branchUsersForCompany
                                                     join a in db.AppUsers on b.AppUserId equals a.AppUserId
                                                     select a).Distinct().ToList();

                foreach (AppUser appUserForCompany in appUsersForCompany)
                {
                    UserAdminView userAdminView = new UserAdminView();
                    userAdminView.AppUserId           = appUserForCompany.AppUserId;
                    userAdminView.FirstName           = appUserForCompany.FirstName;
                    userAdminView.LastName            = appUserForCompany.LastName;
                    userAdminView.AppUserEntityStatus = appUserForCompany.EntityStatus;
                    userAdminView.CurrentBranchId     = appUserForCompany.CurrentBranchId;
                    userAdminView.LoginEmail          = appUserForCompany.LoginEmail;
                    userAdminView.RelatedBranches     = (from rb in relatedBranches
                                                         where (rb.AppUserId == appUserForCompany.AppUserId)
                                                         select rb).ToList();

                    userAdminViewListForUser.Add(userAdminView);
                }
                break;

            case "Manager":     //Get all users for the branches of this user as manager (manager)
                var branchList = (from bu in db.BranchUsers
                                  where (bu.UserId == appUser.AppUserId && bu.UserRole == UserRoleEnum.Manager)
                                  select new { BranchId = bu.BranchId }).Distinct().ToList();

                //var branchUsersForBranch = (from b in db.BranchUsers
                //                            join a in db.AppUsers on b.UserId equals a.AppUserId
                //                            join c in branchList on b.BranchId equals c.BranchId
                //                            where (b.BranchId == appUser.CurrentBranchId && b.EntityStatus == EntityStatusEnum.Active)
                //                            select new { AppUserId = b.UserId, BranchId = b.BranchId, BranchUserId = b.BranchUserId, CurrentBranchId = a.CurrentBranchId, UserRole = b.UserRole }).Distinct().ToList();

                var branchUsersForBranchList = (from bl in branchList
                                                join bu in db.BranchUsers on bl.BranchId equals bu.BranchId
                                                join au in db.AppUsers on bu.UserId equals au.AppUserId
                                                where (bu.CompanyId == branchUser.CompanyId && bu.EntityStatus == EntityStatusEnum.Active)
                                                select new { AppUserId = bu.UserId, BranchId = bu.BranchId, BranchUserId = bu.BranchUserId, CurrentBranchId = au.CurrentBranchId, UserRole = bu.UserRole }).Distinct().ToList();

                foreach (var branchUserForBranch in branchUsersForBranchList)
                {
                    UserAdminRelatedBranchesView relatedBranch = new UserAdminRelatedBranchesView();
                    relatedBranch.AppUserId    = branchUserForBranch.AppUserId;
                    relatedBranch.BranchId     = branchUserForBranch.BranchId;
                    relatedBranch.BranchUserId = branchUserForBranch.BranchUserId;
                    relatedBranch.UserRole     = branchUserForBranch.UserRole;
                    //relatedBranch.BranchUserDetails = BranchUserHelpers.GetBranchUser(db, branchUserForBranch.BranchUserId);
                    Branch branchDetails = BranchHelpers.GetBranch(db, branchUserForBranch.BranchId);

                    relatedBranch.BranchName      = branchDetails.BranchName;
                    relatedBranch.AddressLine1    = branchDetails.AddressLine1;
                    relatedBranch.AddressTownCity = branchDetails.AddressTownCity;
                    relatedBranch.AddressPostcode = branchDetails.AddressPostcode;

                    if (branchUserForBranch.BranchId == branchUserForBranch.CurrentBranchId)
                    {
                        relatedBranch.CurrentBranch = true;
                    }
                    else
                    {
                        relatedBranch.CurrentBranch = false;
                    }

                    relatedBranches.Add(relatedBranch);
                }

                List <AppUser> appUsersForBranchList = (from b in branchUsersForBranchList
                                                        join a in db.AppUsers on b.AppUserId equals a.AppUserId
                                                        select a).Distinct().ToList();

                foreach (AppUser appUserForBranch in appUsersForBranchList)
                {
                    UserAdminView userAdminView = new UserAdminView();
                    userAdminView.AppUserId           = appUserForBranch.AppUserId;
                    userAdminView.FirstName           = appUserForBranch.FirstName;
                    userAdminView.LastName            = appUserForBranch.LastName;
                    userAdminView.AppUserEntityStatus = appUserForBranch.EntityStatus;
                    userAdminView.CurrentBranchId     = appUserForBranch.CurrentBranchId;
                    userAdminView.LoginEmail          = appUserForBranch.LoginEmail;
                    userAdminView.RelatedBranches     = (from rb in relatedBranches
                                                         where (rb.AppUserId == appUserForBranch.AppUserId)
                                                         select rb).ToList();

                    userAdminViewListForUser.Add(userAdminView);
                }

                break;
            }

            return(userAdminViewListForUser);
        }
Exemplo n.º 21
0
        public static OrderEditView GetOrderEditView(ApplicationDbContext db, Guid orderId, IPrincipal user)
        {
            Order              orderDetails       = OrderHelpers.GetOrder(db, orderId);
            AppUser            orderAppUser       = null;
            Branch             orderBranch        = null;
            AppUser            offerAppUser       = null;
            Branch             offerBranch        = null;
            AppUser            listingAppUser     = null;
            Branch             listingBranch      = null;
            Offer              offerDetails       = null;
            AvailableListing   availableListing   = null;
            RequirementListing requirementListing = null;

            if (orderDetails.OrderOriginatorAppUserId != null)
            {
                if (orderDetails.OrderOriginatorAppUserId.Value != Guid.Empty)
                {
                    orderAppUser = AppUserHelpers.GetAppUser(db, orderDetails.OrderOriginatorAppUserId.Value);
                }
            }

            if (orderDetails.OrderOriginatorBranchId != null)
            {
                if (orderDetails.OrderOriginatorBranchId.Value != Guid.Empty)
                {
                    orderBranch = BranchHelpers.GetBranch(db, orderDetails.ListingOriginatorBranchId.Value);
                }
            }

            if (orderDetails.OfferOriginatorAppUserId != null)
            {
                if (orderDetails.OfferOriginatorAppUserId.Value != Guid.Empty)
                {
                    offerAppUser = AppUserHelpers.GetAppUser(db, orderDetails.OfferOriginatorAppUserId.Value);
                }
            }

            if (orderDetails.OfferOriginatorBranchId != null)
            {
                if (orderDetails.OfferOriginatorBranchId.Value != Guid.Empty)
                {
                    offerBranch = BranchHelpers.GetBranch(db, orderDetails.OfferOriginatorBranchId.Value);
                }
            }

            if (orderDetails.ListingOriginatorAppUserId != null)
            {
                if (orderDetails.ListingOriginatorAppUserId.Value != Guid.Empty)
                {
                    listingAppUser = AppUserHelpers.GetAppUser(db, orderDetails.ListingOriginatorAppUserId.Value);
                }
            }

            if (orderDetails.ListingOriginatorBranchId != null)
            {
                if (orderDetails.ListingOriginatorBranchId.Value != Guid.Empty)
                {
                    listingBranch = BranchHelpers.GetBranch(db, orderDetails.ListingOriginatorBranchId.Value);
                }
            }

            if (orderDetails.OfferId != null)
            {
                if (orderDetails.OfferId.Value != Guid.Empty)
                {
                    offerDetails = OfferHelpers.GetOffer(db, orderDetails.OfferId.Value);
                    if (orderDetails.ListingId != null)
                    {
                        if (orderDetails.ListingId.Value != Guid.Empty)
                        {
                            switch (offerDetails.ListingType)
                            {
                            case ListingTypeEnum.Available:
                                availableListing = AvailableListingHelpers.GetAvailableListing(db, orderDetails.ListingId.Value);
                                break;

                            case ListingTypeEnum.Requirement:
                                requirementListing = RequirementListingHelpers.GetRequirementListing(db, orderDetails.ListingId.Value);
                                break;
                            }
                        }
                    }
                }
            }

            OrderEditView view = new OrderEditView()
            {
                OrderId                   = orderDetails.OrderId,
                ListingType               = orderDetails.ListingType,
                OrderQuanity              = orderDetails.OrderQuanity,
                OrderStatus               = orderDetails.OrderStatus,
                OrderCreationDateTime     = orderDetails.OrderCreationDateTime,
                OrderDistributionDateTime = orderDetails.OrderDistributionDateTime,
                OrderDeliveredDateTime    = orderDetails.OrderDeliveredDateTime,
                OrderCollectedDateTime    = orderDetails.OrderCollectedDateTime,
                OrderClosedDateTime       = orderDetails.OrderClosedDateTime,
                OrderAppUser              = orderAppUser,
                OrderBranchDetails        = orderBranch,
                OfferId                   = orderDetails.OfferId.GetValueOrDefault(),
                OfferAppUser              = offerAppUser,
                OfferBranchDetails        = offerBranch,
                OfferDetails              = offerDetails,
                ListingId                 = orderDetails.ListingId.GetValueOrDefault(),
                ListingAppUser            = listingAppUser,
                ListingBranchDetails      = listingBranch,
                AvailableListingDetails   = availableListing,
                RequirementListingDetails = requirementListing
            };

            AppUser thisAppUser = AppUserHelpers.GetAppUser(db, user);
            //If we allow branch trading then differentiate between branches for in/out trading, otherwise it is at company level
            Company thisCompany = CompanyHelpers.GetCompanyForUser(db, user);

            //set Inhouse flag
            view.InhouseOrder = OrderProcessHelpers.SetInhouseFlag(orderDetails, thisAppUser, thisCompany);

            //Set OrderOut flag
            view.OrderOut = OrderProcessHelpers.SetOrderOutFlag(orderDetails, view.InhouseOrder);

            //set buttons
            bool?displayDespatchButton  = null;
            bool?displayDeliveredButton = null;
            bool?displayReceivedButton  = null;
            bool?displayCollectedButton = null;
            bool?displayClosedButton    = null;

            OrderProcessHelpers.SetOrderButtons(db, user, orderDetails, view.OrderOut, out displayDespatchButton, out displayDeliveredButton, out displayReceivedButton, out displayCollectedButton, out displayClosedButton);

            view.DisplayDespatchButton  = displayDespatchButton;
            view.DisplayDeliveredButton = displayDeliveredButton;
            view.DisplayReceivedButton  = displayReceivedButton;
            view.DisplayCollectedButton = displayCollectedButton;
            view.DisplayClosedButton    = displayClosedButton;

            return(view);
        }
Exemplo n.º 22
0
        public static List <UserActionAssignment> CreateActionAssignmentForGroupMembers(ApplicationDbContext db, Guid userActionId, Group group)
        {
            List <UserActionAssignment> list = new List <UserActionAssignment>();

            //get list of members that are accepted within this group only
            List <GroupMember> groupMembers = (from gm in db.GroupMembers
                                               where gm.Status == GroupMemberStatusEnum.Accepted
                                               select gm).ToList();

            //depdending on type of group will depend on the users we need to find, i.e. branch group = members are branches, therefore only find SuperAdmin, Admin or Manager for that branch to send this to
            foreach (GroupMember member in groupMembers)
            {
                switch (group.Type)
                {
                case LevelEnum.Company:
                    List <AppUser> adminUsers = AppUserHelpers.GetAdminAppUsersForCompany(db, member.ReferenceId);
                    foreach (AppUser adminUser in adminUsers)
                    {
                        UserActionAssignment adminUserAssignment = CreateActionAssignment(db, userActionId, adminUser.AppUserId);
                        list.Add(adminUserAssignment);
                    }
                    break;

                case LevelEnum.Branch:
                    List <AppUser> branchUsers = AppUserHelpers.GetManagerAppUsersForBranch(db, member.ReferenceId);
                    foreach (AppUser branchUser in branchUsers)
                    {
                        UserActionAssignment branchUserAssignment = CreateActionAssignment(db, userActionId, branchUser.AppUserId);
                        list.Add(branchUserAssignment);
                    }
                    //Note, Admin users can also approve these requests so list them in the assignment list also
                    List <AppUser> adminUsersForBranchApproval = AppUserHelpers.GetAdminAppUsersForCompany(db, BranchHelpers.GetBranch(member.ReferenceId).CompanyId);
                    foreach (AppUser adminUser in adminUsersForBranchApproval)
                    {
                        //Don't duplicate user entries
                        if (GetActionAssignmentForActionAndUser(db, userActionId, adminUser.AppUserId) == null)
                        {
                            UserActionAssignment adminUserAssignment = CreateActionAssignment(db, userActionId, adminUser.AppUserId);
                            list.Add(adminUserAssignment);
                        }
                    }
                    break;

                case LevelEnum.User:
                    UserActionAssignment assignment = CreateActionAssignment(db, userActionId, member.ReferenceId);
                    list.Add(assignment);
                    break;
                }
            }

            return(list);
        }
Exemplo n.º 23
0
        public static AppUserEditView GetAppUserEditViewForUser(ApplicationDbContext db, AppUser appUserDetails)
        {
            Branch     branch     = BranchHelpers.GetBranch(db, appUserDetails.CurrentBranchId);
            BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, appUserDetails.AppUserId, appUserDetails.CurrentBranchId);

            AppUserSettings appUserSettings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserDetails.AppUserId);

            AppUserEditView view = new AppUserEditView()
            {
                AppUserId                                           = appUserDetails.AppUserId,
                FirstName                                           = appUserDetails.FirstName,
                LastName                                            = appUserDetails.LastName,
                EntityStatus                                        = appUserDetails.EntityStatus,
                PrivacyLevel                                        = appUserDetails.PrivacyLevel,
                SelectedBranchId                                    = appUserDetails.CurrentBranchId,
                UserRole                                            = branchUser.UserRole,
                AppUserSettingsId                                   = appUserSettings.AppUserSettingsId,
                BranchName                                          = branch.BranchName,
                BranchBusinessType                                  = branch.BusinessType,
                BranchAddressLine1                                  = branch.AddressLine1,
                BranchAddressLine2                                  = branch.AddressLine2,
                BranchAddressLine3                                  = branch.AddressLine3,
                BranchAddressTownCity                               = branch.AddressTownCity,
                BranchAddressCounty                                 = branch.AddressCounty,
                BranchAddressPostcode                               = branch.AddressPostcode,
                CampaignDashboardMaxDistance                        = appUserSettings.CampaignDashboardMaxDistance,
                CampaignDashboardMaxAge                             = appUserSettings.CampaignDashboardMaxAge,
                RequiredListingDashboardMaxDistance                 = appUserSettings.RequiredListingDashboardMaxDistance,
                RequiredListingDashboardMaxAge                      = appUserSettings.RequiredListingDashboardMaxAge,
                AvailableListingDashboardMaxDistance                = appUserSettings.AvailableListingDashboardMaxDistance,
                AvailableListingDashboardMaxAge                     = appUserSettings.AvailableListingDashboardMaxAge,
                CampaignDashboardExternalSelectionLevel             = appUserSettings.CampaignDashboardExternalSelectionLevel,
                RequiredListingDashboardExternalSelectionLevel      = appUserSettings.RequiredListingDashboardExternalSelectionLevel,
                AvailableListingDashboardExternalSelectionLevel     = appUserSettings.AvailableListingDashboardExternalSelectionLevel,
                CampaignGeneralInfoDisplayMyUserListings            = appUserSettings.CampaignGeneralInfoDisplayMyUserListings,
                CampaignGeneralInfoDisplayMyBranchListings          = appUserSettings.CampaignGeneralInfoDisplayMyBranchListings,
                CampaignGeneralInfoDisplayMyCompanyListings         = appUserSettings.CampaignGeneralInfoDisplayMyCompanyListings,
                CampaignGeneralInfoDisplayBlockedListings           = appUserSettings.CampaignGeneralInfoDisplayBlockedListings,
                CampaignGeneralInfoMaxDistance                      = appUserSettings.CampaignGeneralInfoMaxDistance,
                RequiredListingGeneralInfoDisplayMyUserListings     = appUserSettings.RequiredListingGeneralInfoDisplayMyUserListings,
                RequiredListingGeneralInfoDisplayMyBranchListings   = appUserSettings.RequiredListingGeneralInfoDisplayMyBranchListings,
                RequiredListingGeneralInfoDisplayMyCompanyListings  = appUserSettings.RequiredListingGeneralInfoDisplayMyCompanyListings,
                RequiredListingGeneralInfoDisplayBlockedListings    = appUserSettings.RequiredListingGeneralInfoDisplayBlockedListings,
                RequiredListingGeneralInfoMaxDistance               = appUserSettings.RequiredListingGeneralInfoMaxDistance,
                AvailableListingGeneralInfoDisplayMyUserListings    = appUserSettings.AvailableListingGeneralInfoDisplayMyUserListings,
                AvailableListingGeneralInfoDisplayMyBranchListings  = appUserSettings.AvailableListingGeneralInfoDisplayMyBranchListings,
                AvailableListingGeneralInfoDisplayMyCompanyListings = appUserSettings.AvailableListingGeneralInfoDisplayMyCompanyListings,
                AvailableListingGeneralInfoDisplayBlockedListings   = appUserSettings.AvailableListingGeneralInfoDisplayBlockedListings,
                AvailableListingGeneralInfoMaxDistance              = appUserSettings.AvailableListingGeneralInfoMaxDistance,
                CampaignManageViewInternalSelectionLevel            = appUserSettings.CampaignManageViewInternalSelectionLevel,
                RequiredListingManageViewInternalSelectionLevel     = appUserSettings.RequiredListingManageViewInternalSelectionLevel,
                AvailableListingManageViewInternalSelectionLevel    = appUserSettings.AvailableListingManageViewInternalSelectionLevel,
                OffersManageViewInternalSelectionLevel              = appUserSettings.OffersManageViewInternalSelectionLevel,
                OffersAcceptedAuthorisationManageViewLevel          = appUserSettings.OffersAcceptedAuthorisationManageViewLevel,
                OffersRejectedAuthorisationManageViewLevel          = appUserSettings.OffersRejectedAuthorisationManageViewLevel,
                OffersReturnedAuthorisationManageViewLevel          = appUserSettings.OffersReturnedAuthorisationManageViewLevel,
                OrdersManageViewInternalSelectionLevel              = appUserSettings.OrdersManageViewInternalSelectionLevel,
                OrdersDespatchedAuthorisationManageViewLevel        = appUserSettings.OrdersDespatchedAuthorisationManageViewLevel,
                OrdersDeliveredAuthorisationManageViewLevel         = appUserSettings.OrdersDeliveredAuthorisationManageViewLevel,
                OrdersCollectedAuthorisationManageViewLevel         = appUserSettings.OrdersCollectedAuthorisationManageViewLevel,
                OrdersClosedAuthorisationManageViewLevel            = appUserSettings.OrdersClosedAuthorisationManageViewLevel,
                CampaignGeneralInfoExternalSelectionLevel           = appUserSettings.CampaignGeneralInfoExternalSelectionLevel,
                RequiredListingGeneralInfoExternalSelectionLevel    = appUserSettings.RequiredListingGeneralInfoExternalSelectionLevel,
                AvailableListingGeneralInfoExternalSelectionLevel   = appUserSettings.AvailableListingGeneralInfoExternalSelectionLevel,
                GroupListViewsForUserOnly                           = GroupViewHelpers.GetGroupEditViewForForUserOnly(db, appUserDetails.AppUserId),
                UserFriendListView                                  = FriendViewHelpers.GetFriendViewByType(db, appUserDetails.AppUserId, LevelEnum.User),
                UserBranchFriendListView                            = FriendViewHelpers.GetFriendViewByType(db, appUserDetails.AppUserId, LevelEnum.Branch),
                UserCompanyFriendListView                           = FriendViewHelpers.GetFriendViewByType(db, appUserDetails.AppUserId, LevelEnum.Company),
                UserBlockListView                                   = BlockViewHelpers.GetBlockViewByType(db, appUserDetails.AppUserId, LevelEnum.User),
                UserBranchBlockListView                             = BlockViewHelpers.GetBlockViewByType(db, appUserDetails.AppUserId, LevelEnum.Branch),
                UserCompanyBlockListView                            = BlockViewHelpers.GetBlockViewByType(db, appUserDetails.AppUserId, LevelEnum.Company)
            };

            return(view);
        }
Exemplo n.º 24
0
        public static RequirementListingEditView GetRequirementListingEditView(ApplicationDbContext db, Guid listingId, IPrincipal user)
        {
            RequirementListing requirementListing = RequirementListingHelpers.GetRequirementListing(db, listingId);
            AppUser            listingAppUser     = AppUserHelpers.GetAppUser(db, requirementListing.ListingOriginatorAppUserId);
            Branch             listingBranch      = BranchHelpers.GetBranch(db, requirementListing.ListingOriginatorBranchId);
            Company            listingCompany     = CompanyHelpers.GetCompany(db, requirementListing.ListingOriginatorCompanyId);
            Campaign           listingCampaign    = null;
            Guid     campaignId            = Guid.Empty;
            string   campaignName          = "";
            string   campaignStrapline     = "";
            string   campaignDescription   = "";
            DateTime?campaignStartDateTime = null;
            DateTime?campaignEndDateTime   = null;

            ViewButtons buttons = ViewButtonsHelpers.GetAvailableButtonsForSingleView(db, listingAppUser, listingBranch, listingCompany, user);

            if (requirementListing.CampaignId != null)
            {
                if (requirementListing.CampaignId.Value != Guid.Empty)
                {
                    listingCampaign       = CampaignHelpers.GetCampaign(db, requirementListing.CampaignId.Value);
                    campaignId            = listingCampaign.CampaignId;
                    campaignName          = listingCampaign.Name;
                    campaignStrapline     = listingCampaign.StrapLine;
                    campaignDescription   = listingCampaign.Description;
                    campaignStartDateTime = listingCampaign.CampaignStartDateTime;
                    campaignEndDateTime   = listingCampaign.CampaignEndDateTime;
                }
            }

            RequirementListingEditView view = new RequirementListingEditView()
            {
                ListingId           = requirementListing.ListingId,
                ItemDescription     = requirementListing.ItemDescription,
                ItemCategory        = requirementListing.ItemCategory,
                ItemType            = requirementListing.ItemType,
                QuantityRequired    = requirementListing.QuantityRequired,
                QuantityFulfilled   = requirementListing.QuantityFulfilled,
                QuantityOutstanding = requirementListing.QuantityOutstanding,
                UoM                       = requirementListing.UoM,
                RequiredFrom              = requirementListing.RequiredFrom,
                RequiredTo                = requirementListing.RequiredTo,
                AcceptDamagedItems        = requirementListing.AcceptDamagedItems,
                AcceptOutOfDateItems      = requirementListing.AcceptOutOfDateItems,
                CollectionAvailable       = requirementListing.CollectionAvailable,
                ListingStatus             = requirementListing.ListingStatus,
                ListingOriginatorDateTime = requirementListing.ListingOriginatorDateTime,
                ListingAppUser            = listingAppUser,
                ListingBranchDetails      = listingBranch,
                ListingCompanyDetails     = listingCompany,
                SelectedCampaignId        = campaignId,
                CampaignName              = campaignName,
                CampaignStrapLine         = campaignStrapline,
                CampaignDescription       = campaignStrapline,
                CampaignStartDateTime     = campaignStartDateTime,
                CampaignEndDateTime       = campaignEndDateTime,
                Buttons                   = buttons
            };

            return(view);
        }
Exemplo n.º 25
0
        public static ViewButtons GetAvailableButtonsForSingleView(ApplicationDbContext db, AppUser appUser, Branch branch, Company company, IPrincipal user)
        {
            //Build initial list
            ViewButtons buttons = new ViewButtons()
            {
                CompanyBlockButton      = false,
                CompanyAddFriendButton  = false,
                CompanyAddToGroupButton = false,
                BranchBlockButton       = false,
                BranchAddFriendButton   = false,
                BranchAddToGroupButton  = false,
                UserBlockButton         = false,
                UserAddFriendButton     = false,
                UserAddToGroupButton    = false
            };

            //First: check this is not our listing
            AppUser currentUser = AppUserHelpers.GetAppUser(db, user);

            if (currentUser.AppUserId == appUser.AppUserId)
            {
                return(buttons);
            }

            //Second: check the branch is not our branch, else return current button settings
            if (currentUser.CurrentBranchId == branch.BranchId)
            {
                return(buttons);
            }

            //Third: check if the Company allows interbranch dealing, if not and company level are the same return current button settings
            Branch currentUserBranch = BranchHelpers.GetBranch(db, currentUser.CurrentBranchId);

            if (!company.AllowBranchTrading && currentUserBranch.CompanyId == company.CompanyId)
            {
                return(buttons);
            }

            //Now validate for button status depending on type of user for this branch user combo
            BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, appUser.AppUserId, branch.BranchId, company.CompanyId);

            switch (branchUser.UserRole)
            {
            //Note - must be in this order as there are override checks the lower down the ranking/role you go
            case UserRoleEnum.SuperUser:
            case UserRoleEnum.Admin:
                buttons = SetCompanyButtons(db, buttons, company.CompanyId, currentUserBranch.CompanyId);
                buttons = SetBranchButtons(db, buttons, branch.BranchId, currentUser.CurrentBranchId);
                buttons = SetUserButtons(db, buttons, appUser.AppUserId, currentUser.AppUserId);
                break;

            case UserRoleEnum.Manager:
                buttons = SetBranchButtons(db, buttons, branch.BranchId, currentUser.CurrentBranchId);
                buttons = SetUserButtons(db, buttons, appUser.AppUserId, currentUser.AppUserId);
                break;

            case UserRoleEnum.User:
                buttons = SetUserButtons(db, buttons, appUser.AppUserId, currentUser.AppUserId);
                break;
            }

            return(buttons);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Build the list of assignments for this Action.  At user level there is the one, at Branch level there is the 'Manager' of the branch and the 'Admin' of the company, and at
        ///     Admin level there is the 'Admin' of the company.  There could be multiple for Branch and Admin levels
        /// </summary>
        /// <param name="db"></param>
        /// <param name="level">level of request, User, Branch, Company</param>
        /// <param name="ofReferenceId">id based on level, so AppUserId, BranchId, CompanyId</param>
        /// <param name="byReferenceId">id based on level, so AppUserId, BranchId, CompanyId</param>
        /// <returns></returns>
        public static List <UserActionAssignment> CreateUserAssignmentForAction(ApplicationDbContext db, Guid userActionId, LevelEnum level, Guid ofReferenceId, Guid byReferenceId)
        {
            List <UserActionAssignment> list = new List <UserActionAssignment>();

            switch (level)
            {
            case LevelEnum.Company:
                List <AppUser> adminUsers = AppUserHelpers.GetAdminAppUsersForCompany(db, ofReferenceId);
                foreach (AppUser adminUser in adminUsers)
                {
                    UserActionAssignment adminUserAssignment = CreateActionAssignment(db, userActionId, adminUser.AppUserId);
                    list.Add(adminUserAssignment);
                }
                break;

            case LevelEnum.Branch:
                List <AppUser> branchUsers = AppUserHelpers.GetManagerAppUsersForBranch(db, ofReferenceId);
                foreach (AppUser branchUser in branchUsers)
                {
                    UserActionAssignment branchUserAssignment = CreateActionAssignment(db, userActionId, branchUser.AppUserId);
                    list.Add(branchUserAssignment);
                }
                //Note, Admin users can also approve these requests so list them in the assignment list also
                List <AppUser> adminUsersForBranchApproval = AppUserHelpers.GetAdminAppUsersForCompany(db, BranchHelpers.GetBranch(ofReferenceId).CompanyId);
                foreach (AppUser adminUser in adminUsersForBranchApproval)
                {
                    //Don't duplicate user entries
                    if (GetActionAssignmentForActionAndUser(db, userActionId, adminUser.AppUserId) == null)
                    {
                        UserActionAssignment adminUserAssignment = CreateActionAssignment(db, userActionId, adminUser.AppUserId);
                        list.Add(adminUserAssignment);
                    }
                }
                break;

            case LevelEnum.User:
                UserActionAssignment assignment = CreateActionAssignment(db, userActionId, ofReferenceId);
                list.Add(assignment);
                break;
            }

            return(list);
        }