コード例 #1
0
        public static Group CreateGroup(ApplicationDbContext db, GroupViewCreateModel model, IPrincipal user)
        {
            Group group = new Group()
            {
                GroupId                       = Guid.NewGuid(),
                Name                          = model.Name,
                VisibilityLevel               = model.VisibilityLevel,
                InviteLevel                   = model.InviteLevel,
                AcceptanceLevel               = model.AcceptanceLevel,
                EntityStatus                  = EntityStatusEnum.Active,
                RecordChange                  = RecordChangeEnum.NewRecord,
                RecordChangeOn                = DateTime.Now,
                RecordChangeBy                = AppUserHelpers.GetAppUserIdFromUser(user),
                GroupOriginatorAppUserId      = AppUserHelpers.GetAppUserIdFromUser(user),
                GroupOriginatorOrganisationId = AppUserHelpers.GetOrganisationIdFromUser(user),
                GroupOriginatorDateTime       = DateTime.Now
            };

            db.Groups.Add(group);
            db.SaveChanges();

            //Add user Organisation as the initial group member
            GroupMembersHelpers.CreateGroupMember(db, group.GroupId, group.GroupOriginatorOrganisationId, user);

            return(group);
        }
コード例 #2
0
        public static List <GroupMemberViewCreateModel> GetGroupMembersViewCreateForGroup(ApplicationDbContext db, Guid groupId)
        {
            List <GroupMember> groupMembersForGroup = GroupMembersHelpers.GetGroupMembersForGroup(db, groupId);
            List <GroupMemberViewCreateModel> list  = BuildGroupMemberViewCreateListFromGroupMemberList(db, groupMembersForGroup);

            return(list);
        }
コード例 #3
0
        public static List <AvailableListing> FilterAvailableListingsByGroup(ApplicationDbContext db, List <AvailableListing> currentList, Guid organisationId)
        {
            //Get the group Member IDs from groups that this user/organisation are part of, so we can remove them from the list
            List <Guid> groupMemberOrgIds = GroupMembersHelpers.GetGroupsMembersOrgGuidsForGroupsFromOrg(db, organisationId);

            if (groupMemberOrgIds.Count == 0)
            {
                return(new List <AvailableListing>());
            }
            else
            {
                //Select from currentList only those records containing the list of found orgIds
                return(currentList.Where(x => groupMemberOrgIds.Contains(x.ListingOriginatorOrganisationId)).ToList());
            }
        }
コード例 #4
0
        public static SelectList OrganisationsListForGroupDropDown(ApplicationDbContext db, Guid groupId)
        {
            List <Organisation> allOrganisations = OrganisationHelpers.GetAllOrganisations(db);
            List <GroupMember>  members          = GroupMembersHelpers.GetGroupMembersForGroup(db, groupId);

            //remove the group orgs from the allOrganisation list
            foreach (GroupMember member in members)
            {
                Organisation org = OrganisationHelpers.GetOrganisation(db, member.OrganisationId);
                allOrganisations.Remove(org);
            }

            //Build custom selectable data to hold org name and address
            return(new SelectList(
                       allOrganisations.Select(
                           o => new
            {
                OrganisationId = o.OrganisationId,
                OrganisationDetails = o.OrganisationName + ": " + o.AddressLine1 + ", " + o.AddressTownCity
            }), "OrganisationId", "OrganisationDetails"));
        }
コード例 #5
0
        public static AvailableListingGeneralViewListModel GetAvailableListingGeneralViewListModel(ApplicationDbContext db, IPrincipal user, int?maxDistance, double?maxAge)
        {
            List <AvailableListingGeneralViewModel> list = new List <AvailableListingGeneralViewModel>();

            //Get user so we can get the settings to initialise the search on the screen
            AppUser      currentUser = AppUserHelpers.GetAppUser(db, user);
            Organisation currentOrg  = OrganisationHelpers.GetOrganisation(db, currentUser.OrganisationId);

            //set the search criteria.  If nothing passed in then take the values from the settings.  If values past in then this is the dynamic changes made on the list screen and resubmitted
            int?   maxDistanceFilter = maxDistance ?? currentUser.MaxDistanceFilter ?? 1500;
            double?maxAgeFilter      = maxAge ?? currentUser.MaxAgeFilter ?? 9999;

            //Get the group Member IDs from groups that this user/organisation are part of, so we can remove them from the list
            List <Guid> groupMemberOrgIds = null;

            if (currentUser.SelectionLevelFilter == ExternalSearchLevelEnum.Group)
            {
                groupMemberOrgIds = GroupMembersHelpers.GetGroupsMembersOrgGuidsForGroupsFromOrg(db, currentOrg.OrganisationId);
            }

            //build the age filter to apply when building list
            double negativeDays = 0 - maxAgeFilter.Value;
            var    dateCheck    = DateTime.Now.AddDays(negativeDays);

            //build list depending on whether to filter on groups or not (settings, search level = groups)
            if (groupMemberOrgIds == null)
            {
                list = (from al in db.AvailableListings
                        join org in db.Organisations on al.ListingOriginatorOrganisationId equals org.OrganisationId
                        where (al.ListingOriginatorOrganisationId != currentUser.OrganisationId && (al.ListingStatus == ItemEnums.ItemRequiredListingStatusEnum.Open || al.ListingStatus == ItemEnums.ItemRequiredListingStatusEnum.Partial) &&
                               al.ListingOriginatorDateTime >= dateCheck)
                        select new AvailableListingGeneralViewModel()
                {
                    ListingId = al.ListingId,
                    ItemDescription = al.ItemDescription,
                    ItemType = al.ItemType,
                    QuantityOutstanding = al.QuantityOutstanding,
                    UoM = al.UoM,
                    AvailableTo = al.AvailableTo,
                    ItemCondition = al.ItemCondition,
                    ExpiryDate = al.SellByDate ?? al.UseByDate,
                    DeliveryAvailable = al.DeliveryAvailable,
                    SupplierDetails = org.OrganisationName,
                    ListingOriginatorOrganisationId = al.ListingOriginatorOrganisationId,
                    ListingOrganisationPostcode = al.ListingOrganisationPostcode
                }).Distinct().ToList();
            }
            else
            {
                list = (from al in db.AvailableListings
                        join org in db.Organisations on al.ListingOriginatorOrganisationId equals org.OrganisationId
                        join grpmem in groupMemberOrgIds on al.ListingOriginatorOrganisationId equals grpmem
                        where (al.ListingOriginatorOrganisationId != currentUser.OrganisationId && (al.ListingStatus == ItemEnums.ItemRequiredListingStatusEnum.Open || al.ListingStatus == ItemEnums.ItemRequiredListingStatusEnum.Partial) &&
                               al.ListingOriginatorDateTime >= dateCheck)
                        select new AvailableListingGeneralViewModel()
                {
                    ListingId = al.ListingId,
                    ItemDescription = al.ItemDescription,
                    ItemType = al.ItemType,
                    QuantityOutstanding = al.QuantityOutstanding,
                    UoM = al.UoM,
                    AvailableTo = al.AvailableTo,
                    ItemCondition = al.ItemCondition,
                    ExpiryDate = al.SellByDate ?? al.UseByDate,
                    DeliveryAvailable = al.DeliveryAvailable,
                    SupplierDetails = org.OrganisationName,
                    ListingOriginatorOrganisationId = al.ListingOriginatorOrganisationId,
                    ListingOrganisationPostcode = al.ListingOrganisationPostcode
                }).Distinct().ToList();
            }

            //Filter by DISTANCE and add OFFER info also.

            //hold list of organisationIds already checked - set to true if within range
            Dictionary <Guid, bool> listingOrgIds = new Dictionary <Guid, bool>();

            //hold new list from old
            List <AvailableListingGeneralViewModel> newList = new List <AvailableListingGeneralViewModel>();

            foreach (AvailableListingGeneralViewModel item in list)
            {
                //if we have checked this org before then just add or not depending on flag
                if (listingOrgIds.ContainsKey(item.ListingOriginatorOrganisationId))
                {
                    if (listingOrgIds[item.ListingOriginatorOrganisationId])
                    {
                        //quick check for offer
                        Offer offer = OfferHelpers.GetOfferForListingByUser(db, item.ListingId, currentUser.AppUserId, currentOrg.OrganisationId, currentOrg.ListingPrivacyLevel);

                        if (offer == null)
                        {
                            item.OfferQty = 0.00M;
                        }
                        else
                        {
                            item.OfferId  = offer.OfferId;
                            item.OfferQty = offer.CurrentOfferQuantity;
                        }

                        newList.Add(item);
                    }
                }
                else  //add the org to the dictionary with the flag set and add to new list if within range
                {
                    int distanceValue = DistanceHelpers.GetDistance(currentOrg.AddressPostcode, item.ListingOrganisationPostcode);
                    if (distanceValue <= maxDistanceFilter)
                    {
                        listingOrgIds.Add(item.ListingOriginatorOrganisationId, true);

                        //quick check for offer
                        Offer offer = OfferHelpers.GetOfferForListingByUser(db, item.ListingId, currentUser.AppUserId, currentOrg.OrganisationId, currentOrg.ListingPrivacyLevel);

                        if (offer == null)
                        {
                            item.OfferQty = 0.00M;
                        }
                        else
                        {
                            item.OfferId  = offer.OfferId;
                            item.OfferQty = offer.CurrentOfferQuantity;
                        }

                        newList.Add(item);
                    }
                    else
                    {
                        listingOrgIds.Add(item.ListingOriginatorOrganisationId, false);
                    }
                }
            }

            AvailableListingGeneralViewListModel model = new AvailableListingGeneralViewListModel()
            {
                MaxDistance    = maxDistanceFilter,
                MaxAge         = maxAgeFilter,
                EditableFields = newList.Any(x => x.OfferId == null),  //only set if there are no offers in the list
                Listing        = newList
            };

            return(model);
        }