示例#1
0
        public static List <UserActionView> GetActionsForViewsForUser(ApplicationDbContext db, IPrincipal user)
        {
            List <UserActionView> list = new List <UserActionView>();

            List <UserAction> userActionList = UserActionHelpers.GetActionsForUser(db, user);

            foreach (UserAction userAction in userActionList)
            {
                string referenceName = "";

                switch (userAction.ActionLevel)
                {
                case LevelEnum.Company:
                    referenceName = CompanyHelpers.GetCompanyNameTownPostCode(db, userAction.ReferenceKey);
                    break;

                case LevelEnum.Branch:
                    referenceName = BranchHelpers.GetBranchNameTownPostCode(db, userAction.ReferenceKey);
                    break;

                case LevelEnum.User:
                    referenceName = AppUserHelpers.GetAppUserName(db, userAction.ReferenceKey);
                    break;
                }

                string createdByName = "";

                //Get the user that created the action.  Note, this could be at Company or Branch level, so try the user first, if that
                //fails then work through a switch
                try
                {
                    createdByName = AppUserHelpers.GetAppUserName(db, userAction.CreatedBy);
                }
                catch
                {
                    switch (userAction.ActionLevel)
                    {
                    case LevelEnum.Company:
                        createdByName = CompanyHelpers.GetCompanyNameTownPostCode(db, userAction.CreatedBy);
                        break;

                    case LevelEnum.Branch:
                        createdByName = BranchHelpers.GetBranchNameTownPostCode(db, userAction.CreatedBy);
                        break;
                    }
                }

                list.Add(CreateUserActionView(userAction, referenceName, createdByName));
            }

            return(list);
        }
示例#2
0
        public static List <GroupListView> GetGroupListViewsCreatedByUser(ApplicationDbContext db, Guid appUserId)
        {
            List <GroupListView> list = new List <GroupListView>();

            List <Group> allGroupsCreatedByUser = GroupHelpers.GetGroupsCreatedByUser(db, appUserId);

            foreach (Group group in allGroupsCreatedByUser)
            {
                //Get members of the group
                List <GroupMember>         groupMembers     = GroupMemberHelpers.GetMembersForGroup(db, group.GroupId);
                List <GroupMemberListView> groupMembersView = new List <GroupMemberListView>();

                foreach (GroupMember member in groupMembers)
                {
                    string memberName = null;

                    switch (member.Type)
                    {
                    case LevelEnum.User:
                        memberName = AppUserHelpers.GetAppUserName(db, member.ReferenceId);
                        break;

                    case LevelEnum.Branch:
                        memberName = BranchHelpers.GetBranchNameTownPostCode(db, member.ReferenceId);
                        break;

                    case LevelEnum.Company:
                        memberName = CompanyHelpers.GetCompanyNameTownPostCode(db, member.ReferenceId);
                        break;
                    }

                    GroupMemberListView groupMemberListView = new GroupMemberListView()
                    {
                        GroupMember     = member,
                        GroupMemberName = memberName
                    };

                    groupMembersView.Add(groupMemberListView);
                }

                //create view record to add to list of view records
                GroupListView view = new GroupListView();
                view.Group = group;
                view.GroupOriginatorName = AppUserHelpers.GetAppUserName(db, view.Group.GroupOriginatorAppUserId);
                view.Members             = groupMembersView;

                list.Add(view);
            }

            return(list);
        }
示例#3
0
        //Build a NotificationsViewModel record from a Notification
        public static NotificationViewModel CreateNotificationsViewModel(ApplicationDbContext db, Notification notification)
        {
            string referenceInfo = "";

            switch (notification.NotificationType)
            {
            case NotificationTypeEnum.NewOfferReceived:
                Offer offer1 = OfferHelpers.GetOffer(db, notification.ReferenceKey);
                referenceInfo = offer1.ItemDescription + " x " + offer1.CurrentOfferQuantity.ToString();
                break;

            case NotificationTypeEnum.CounterOfferReceived:
                Offer offer2 = OfferHelpers.GetOffer(db, notification.ReferenceKey);
                referenceInfo = offer2.ItemDescription + " x " + offer2.CounterOfferQuantity.ToString();
                break;

            case NotificationTypeEnum.NewOrderReceived:
                Order order = OrderHelpers.GetOrder(db, notification.ReferenceKey);
                switch (order.ListingType)
                {
                case ListingTypeEnum.Available:
                    AvailableListing listingA = AvailableListingHelpers.GetAvailableListing(db, order.ListingId.Value);
                    referenceInfo = listingA.ItemDescription = " x " + order.OrderQuanity;
                    break;

                case ListingTypeEnum.Requirement:
                    RequiredListing listingB = RequiredListingHelpers.GetRequiredListing(db, order.ListingId.Value);
                    referenceInfo = listingB.ItemDescription = " x " + order.OrderQuanity;
                    break;
                }
                break;
            }

            //build view
            NotificationViewModel view = new NotificationViewModel()
            {
                NotificationId          = notification.NotificationId,
                NotificationType        = notification.NotificationType,
                NotificationDescription = notification.NotificationDescription,
                ReferenceInformation    = referenceInfo,
                AppUser   = AppUserHelpers.GetAppUser(db, notification.AppUserId.Value),
                ChangedOn = notification.RecordChangeOn,
                ChangedBy = AppUserHelpers.GetAppUserName(db, notification.RecordChangeBy)
            };

            return(view);
        }
示例#4
0
        public static List <GroupListView> GetGroupListViewsRelevantToUser(ApplicationDbContext db, Guid appUserId)
        {
            List <GroupListView> list = new List <GroupListView>();

            List <Group> allGroupsRelevantUser = new List <Group>();

            //Get user groups containing this user
            allGroupsRelevantUser = GroupHelpers.GetGroupsForUser(db, appUserId);
            //Get branch groups containing this users branches
            List <Branch> usersBranches = BranchHelpers.GetBranchesForUser(db, appUserId);

            foreach (Branch branch in usersBranches)
            {
                List <Group> groups = GroupHelpers.GetGroupsForTypeAndReferenceId(db, LevelEnum.Branch, branch.BranchId);
                foreach (Group group in groups)
                {
                    allGroupsRelevantUser.Add(group);
                }
            }
            //Get company groups containing this users company
            List <Group> companyGroups = GroupHelpers.GetGroupsForTypeAndReferenceId(db, LevelEnum.Company, CompanyHelpers.GetCompanyForUser(db, appUserId).CompanyId);

            foreach (Group group in companyGroups)
            {
                allGroupsRelevantUser.Add(group);
            }


            foreach (Group group in allGroupsRelevantUser)
            {
                //Get members of the group
                List <GroupMember>         groupMembers     = GroupMemberHelpers.GetMembersForGroup(db, group.GroupId);
                List <GroupMemberListView> groupMembersView = new List <GroupMemberListView>();

                foreach (GroupMember member in groupMembers)
                {
                    string memberName = null;

                    switch (member.Type)
                    {
                    case LevelEnum.User:
                        memberName = AppUserHelpers.GetAppUserName(db, member.ReferenceId);
                        break;

                    case LevelEnum.Branch:
                        memberName = BranchHelpers.GetBranchNameTownPostCode(db, member.ReferenceId);
                        break;

                    case LevelEnum.Company:
                        memberName = CompanyHelpers.GetCompanyNameTownPostCode(db, member.ReferenceId);
                        break;
                    }

                    GroupMemberListView groupMemberListView = new GroupMemberListView()
                    {
                        GroupMember     = member,
                        GroupMemberName = memberName
                    };

                    groupMembersView.Add(groupMemberListView);
                }

                //create view record to add to list of view records
                GroupListView view = new GroupListView();
                view.Group = group;
                view.GroupOriginatorName = AppUserHelpers.GetAppUserName(db, view.Group.GroupOriginatorAppUserId);
                view.Members             = groupMembersView;

                list.Add(view);
            }

            return(list);
        }
示例#5
0
        public static OrderViewModel GetOfferViewModel(ApplicationDbContext db, HttpRequestBase request, Guid orderId, string breadcrumb, string callingActionDisplayName, bool displayOnly, string type, bool?recalled, string controllerValue, string actionValue, IPrincipal user)
        {
            AppUser currentUser = AppUserHelpers.GetAppUser(db, user);

            Dictionary <int, string> breadcrumbDictionary = new Dictionary <int, string>();

            breadcrumbDictionary.Add(0, breadcrumb);

            if (!recalled.HasValue || recalled.Value != true)
            {
                GeneralHelpers.GetCallingDetailsFromRequest(request, controllerValue, actionValue, out controllerValue, out actionValue);
            }

            Order order = OrderHelpers.GetOrder(db, orderId);

            string       itemDescription = "";
            ItemTypeEnum itemType        = ItemTypeEnum.Canned;
            string       uoM             = "";

            if (order.ListingType == ListingTypeEnum.Available)
            {
                AvailableListing listing = AvailableListingHelpers.GetAvailableListing(db, order.ListingId.Value);
                itemDescription = listing.ItemDescription;
                itemType        = listing.ItemType;
                uoM             = listing.UoM;
            }
            else
            {
                RequiredListing listing = RequiredListingHelpers.GetRequiredListing(db, order.ListingId.Value);
                itemDescription = listing.ItemDescription;
                itemType        = listing.ItemType;
                uoM             = listing.UoM;
            }

            OrderViewModel model = new OrderViewModel()
            {
                DisplayOnly          = displayOnly,
                Breadcrumb           = breadcrumb,
                BreadcrumbDictionary = breadcrumbDictionary,
                Type                          = type,
                OrderId                       = order.OrderId,
                ListingType                   = order.ListingType,
                ItemDescription               = itemDescription,
                ItemType                      = itemType,
                UoM                           = uoM,
                OrderQuanity                  = order.OrderQuanity,
                OrderInStatus                 = order.OrderInStatus,
                OrderOutStatus                = order.OrderOutStatus,
                OrderCreationDateTime         = order.OrderCreationDateTime,
                OrderDistributionDateTime     = order.OrderDistributionDateTime,
                OrderDistributedBy            = AppUserHelpers.GetAppUserName(db, order.OrderDistributedBy),
                OrderDeliveredDateTime        = order.OrderDeliveredDateTime,
                OrderDeliveredBy              = AppUserHelpers.GetAppUserName(db, order.OrderDeliveredBy),
                OrderCollectedDateTime        = order.OrderCollectedDateTime,
                OrderCollectedBy              = AppUserHelpers.GetAppUserName(db, order.OrderCollectedBy),
                OrderReceivedDateTime         = order.OrderReceivedDateTime,
                OrderReceivedBy               = AppUserHelpers.GetAppUserName(db, order.OrderReceivedBy),
                OrderInClosedDateTime         = order.OrderInClosedDateTime,
                OrderInClosedBy               = AppUserHelpers.GetAppUserName(db, order.OrderInClosedBy),
                OrderOutClosedDateTime        = order.OrderOutClosedDateTime,
                OrderOutClosedBy              = AppUserHelpers.GetAppUserName(db, order.OrderOutClosedBy),
                OrderOriginatorAppUser        = AppUserHelpers.GetAppUserName(db, order.OrderOriginatorAppUserId),
                OrderOriginatorOrganisation   = OrganisationHelpers.GetOrganisationName(db, order.OrderOriginatorOrganisationId),
                OrderOriginatorDateTime       = order.OrderOriginatorDateTime,
                OfferId                       = order.OfferId,
                OfferOriginatorAppUser        = AppUserHelpers.GetAppUserName(db, order.OfferOriginatorAppUserId),
                OfferOriginatorOrganisation   = OrganisationHelpers.GetOrganisationName(db, order.OfferOriginatorOrganisationId),
                ListingId                     = order.ListingId,
                ListingOriginatorAppUser      = AppUserHelpers.GetAppUserName(db, order.ListingOriginatorAppUserId),
                ListingOriginatorOrganisation = OrganisationHelpers.GetOrganisationName(db, order.ListingOriginatorOrganisationId),
                CallingAction                 = actionValue,
                CallingActionDisplayName      = callingActionDisplayName,
                CallingController             = controllerValue,
                BreadcrumbTrail               = breadcrumbDictionary
            };

            return(model);
        }
示例#6
0
        public static List <BlockView> GetBlockViewByType(ApplicationDbContext db, Guid appUserId, LevelEnum type)
        {
            List <BlockView> list = new List <BlockView>();

            List <Block> blockList = null;

            //Depending on type passed through will depend on what level of blocks we are collecting
            switch (type)
            {
            case LevelEnum.User:
                blockList = BlockHelpers.GetBlocksCreatedByUser(db, appUserId);
                break;

            case LevelEnum.Branch:
                blockList = BlockHelpers.GetBlocksCreatedByUserBranches(db, appUserId);
                break;

            case LevelEnum.Company:
                blockList = BlockHelpers.GetBlocksCreatedByUserCompany(db, appUserId);
                break;
            }

            foreach (Block block in blockList)
            {
                //get the user/branch/company names depending on the block type
                string nameBy = "";
                string nameOn = "";

                switch (block.Type)
                {
                case LevelEnum.User:
                    nameBy = AppUserHelpers.GetAppUserName(db, block.BlockedById);
                    nameOn = AppUserHelpers.GetAppUserName(db, block.BlockedOfId);
                    break;

                case LevelEnum.Branch:
                    nameBy = BranchHelpers.GetBranchNameTownPostCode(db, block.BlockedById);
                    nameOn = BranchHelpers.GetBranchNameTownPostCode(db, block.BlockedOfId);
                    break;

                case LevelEnum.Company:
                    nameBy = CompanyHelpers.GetCompanyNameTownPostCode(db, block.BlockedById);
                    nameOn = CompanyHelpers.GetCompanyNameTownPostCode(db, block.BlockedOfId);
                    break;
                }

                string blockedByUserName = AppUserHelpers.GetAppUserName(db, block.BlockedByUserId);

                bool blockedByLoggedInUser = false;

                if (block.BlockedByUserId == appUserId)
                {
                    blockedByLoggedInUser = true;
                }

                BlockView view = new BlockView()
                {
                    BlockId               = block.BlockId,
                    Type                  = block.Type,
                    BlockedByName         = nameBy,
                    BlockedByUserName     = blockedByUserName,
                    BlockedOfName         = nameOn,
                    BlockedOn             = block.BlockedOn,
                    BlockedByLoggedInUser = blockedByLoggedInUser
                };

                list.Add(view);
            }

            return(list);
        }
示例#7
0
        public static List <FriendView> GetFriendViewByType(ApplicationDbContext db, Guid appUserId, LevelEnum type)
        {
            List <FriendView> list = new List <FriendView>();

            List <Friend> friendList = null;

            //Depending on type passed through will depend on what level of friends we are collecting
            switch (type)
            {
            case LevelEnum.User:
                friendList = FriendHelpers.GetFriendsCreatedByUser(db, appUserId);
                break;

            case LevelEnum.Branch:
                friendList = FriendHelpers.GetFriendsCreatedByUserBranches(db, appUserId);
                break;

            case LevelEnum.Company:
                friendList = FriendHelpers.GetFriendsCreatedByUserCompany(db, appUserId);
                break;
            }

            foreach (Friend friend in friendList)
            {
                //get the user/branch/company names depending on the block type
                string nameBy = "";
                string nameOn = "";

                switch (friend.Type)
                {
                case LevelEnum.User:
                    nameBy = AppUserHelpers.GetAppUserName(db, friend.RequestedById);
                    nameOn = AppUserHelpers.GetAppUserName(db, friend.RequestedOfId);
                    break;

                case LevelEnum.Branch:
                    nameBy = BranchHelpers.GetBranchNameTownPostCode(db, friend.RequestedById);
                    nameOn = BranchHelpers.GetBranchNameTownPostCode(db, friend.RequestedOfId);
                    break;

                case LevelEnum.Company:
                    nameBy = CompanyHelpers.GetCompanyNameTownPostCode(db, friend.RequestedById);
                    nameOn = CompanyHelpers.GetCompanyNameTownPostCode(db, friend.RequestedOfId);
                    break;
                }

                string friendedByUserName = AppUserHelpers.GetAppUserName(db, friend.RequestedByUserId);

                bool friendedByLoggedInUser = false;

                if (friend.RequestedByUserId == appUserId)
                {
                    friendedByLoggedInUser = true;
                }

                FriendView view = new FriendView()
                {
                    FriendId               = friend.FriendId,
                    Type                   = friend.Type,
                    RequestedByName        = nameBy,
                    RequestedByUserName    = friendedByUserName,
                    RequestedOfName        = nameOn,
                    Status                 = friend.Status,
                    RequestedOn            = friend.RequestedOn,
                    AccceptedOn            = friend.AccceptedOn,
                    RejectedOn             = friend.RequestedOn,
                    ClosedOn               = friend.ClosedOn,
                    ClosedBy               = friend.ClosedBy,
                    FriendedByLoggedInUser = friendedByLoggedInUser
                };

                list.Add(view);
            }

            return(list);
        }
示例#8
0
        public static OfferViewModel GetOfferViewModel(ApplicationDbContext db, HttpRequestBase request, Guid offerId, string breadcrumb, string callingActionDisplayName, bool displayOnly, string type, bool?recalled, string controllerValue, string actionValue, IPrincipal user)
        {
            AppUser currentUser = AppUserHelpers.GetAppUser(db, user);
            Dictionary <int, string> breadcrumbDictionary = new Dictionary <int, string>();

            breadcrumbDictionary.Add(0, breadcrumb);

            if (!recalled.HasValue || recalled.Value != true)
            {
                GeneralHelpers.GetCallingDetailsFromRequest(request, controllerValue, actionValue, out controllerValue, out actionValue);
            }

            Offer offer = OfferHelpers.GetOffer(db, offerId);

            OfferViewModel model = new OfferViewModel()
            {
                DisplayOnly          = displayOnly,
                Breadcrumb           = breadcrumb,
                BreadcrumbDictionary = breadcrumbDictionary,
                Type                                 = type,
                OfferId                              = offer.OfferId,
                ListingId                            = offer.ListingId,
                ListingType                          = offer.ListingType,
                OfferStatus                          = offer.OfferStatus,
                ItemDescription                      = offer.ItemDescription,
                QuantityOutstanding                  = OfferViewHelpers.GetListingQuantityForListingIdListingType(db, offer.ListingId, offer.ListingType),
                CurrentOfferQuantity                 = offer.CurrentOfferQuantity,
                PreviousOfferQuantity                = offer.PreviousOfferQuantity,
                CounterOfferQuantity                 = offer.CounterOfferQuantity,
                PreviousCounterOfferQuantity         = offer.PreviousCounterOfferQuantity,
                OfferOriginatorAppUser               = AppUserHelpers.GetAppUserName(db, offer.OfferOriginatorAppUserId),
                OfferOriginatorOrganisation          = OrganisationHelpers.GetOrganisationName(db, offer.OfferOriginatorOrganisationId),
                OfferOriginatorDateTime              = offer.OfferOriginatorDateTime,
                YourOrganisationId                   = currentUser.OrganisationId,
                OfferOriginatorOrganisationId        = offer.OfferOriginatorOrganisationId,
                RejectedBy                           = AppUserHelpers.GetAppUserName(db, offer.RejectedBy),
                RejectedOn                           = offer.RejectedOn,
                LastOfferOriginatorAppUser           = AppUserHelpers.GetAppUserName(db, offer.LastOfferOriginatorAppUserId),
                LastOfferOriginatorDateTime          = offer.LastOfferOriginatorDateTime,
                ListingOriginatorAppUser             = AppUserHelpers.GetAppUserName(db, offer.ListingOriginatorAppUserId),
                ListingOriginatorOrganisation        = OrganisationHelpers.GetOrganisationName(db, offer.ListingOriginatorOrganisationId),
                ListingOriginatorDateTime            = offer.ListingOriginatorDateTime,
                CounterOfferOriginatorAppUser        = AppUserHelpers.GetAppUserName(db, offer.CounterOfferOriginatorAppUserId),
                CounterOfferOriginatorOrganisation   = OrganisationHelpers.GetOrganisationName(db, offer.CounterOfferOriginatorOrganisationId),
                CounterOfferOriginatorDateTime       = offer.CounterOfferOriginatorDateTime,
                CounterOfferOriginatorOrganisationId = offer.CounterOfferOriginatorOrganisationId,
                LastCounterOfferOriginatorAppUser    = AppUserHelpers.GetAppUserName(db, offer.LastCounterOfferOriginatorAppUserId),
                LastCounterOfferOriginatorDateTime   = offer.LastCounterOfferOriginatorDateTime,
                OrderOriginatorAppUser               = AppUserHelpers.GetAppUserName(db, offer.OrderOriginatorAppUserId),
                OrderOriginatorOrganisation          = OrganisationHelpers.GetOrganisationName(db, offer.OrderOriginatorOrganisationId),
                OrderOriginatorDateTime              = offer.OrderOriginatorDateTime,
                CallingAction                        = actionValue,
                CallingActionDisplayName             = callingActionDisplayName,
                CallingController                    = controllerValue,
                BreadcrumbTrail                      = breadcrumbDictionary
            };

            if (displayOnly)
            {
                model.EditableQuantity = false;
            }
            else
            {
                if (type == "created")
                {
                    model.EditableQuantity = offer.CurrentOfferQuantity == 0;
                }
                else if (type == "received")
                {
                    model.EditableQuantity = offer.CurrentOfferQuantity > 0;
                }
            }

            return(model);
        }