public override async Task <int> DeleteAsync(params object[] id)
        {
            var resourcePoolId = (int)id[0];

            // Load the resource pool into the context with its child items, otherwise it fails to delete due to Foreign Key exception
            //var resourcePool = AllLiveIncluding(item => item.SectorSet)
            //    .SingleOrDefault(item => item.Id == resourcePoolId);
            // TODO?
            var resourcePool = AllLive.SingleOrDefault(item => item.Id == resourcePoolId);

            if (resourcePool == null)
            {
                return(0);
            }

            return(await base.DeleteAsync(resourcePoolId));
        }
Example #2
0
        void UpdateResourcePoolComputedFields(ResourcePool resourcePool)
        {
            // Rating count
            var userCellQuery = UserElementCellStore.AllLive
                                .Where(item => item.ElementCell.ElementField.IndexEnabled &&
                                       item.ElementCell.ElementField.Element.ResourcePool.Id == resourcePool.Id)
                                .Select(item => item.User);

            var userFieldQuery = UserElementFieldStore.AllLive
                                 .Where(item => item.ElementField.IndexEnabled &&
                                        item.ElementField.Element.ResourcePool.Id == resourcePool.Id)
                                 .Select(item => item.User);

            var userResourcePoolQuery = UserResourcePoolStore.AllLive
                                        .Where(item => !item.ResourcePool.UseFixedResourcePoolRate &&
                                               item.ResourcePool.Id == resourcePool.Id)
                                        .Select(item => item.User);

            var ratingCount = userCellQuery.Union(userFieldQuery.Union(userResourcePoolQuery))
                              .Distinct()
                              .Count();

            resourcePool.RatingCount = ratingCount;

            // Resource pool rate
            var list = AllLive.Include(item => item.UserResourcePoolSet)
                       .Where(item => item.Id == resourcePool.Id)
                       .AsEnumerable();

            foreach (var item in list)
            {
                item.ResourcePoolRateTotal = item.UserResourcePoolSet.Sum(userResourcePool => userResourcePool.ResourcePoolRate);
                item.ResourcePoolRateCount = item.UserResourcePoolSet.Count();
            }
            ;
        }