Exemple #1
0
        private Deal GetById(int id, User user, Permission permission)
        {
            var type = user.GetPermissionDistributionType(permission);

            // если права нет - то сразу возвращаем null
            if (type == PermissionDistributionType.None)
            {
                return(null);
            }
            else
            {
                var deal = dealRepository.GetById(id);

                if (type == PermissionDistributionType.All)
                {
                    return(deal);
                }
                else
                {
                    var contains = user.Teams.SelectMany(x => x.Deals).Contains(deal);

                    if ((type == PermissionDistributionType.Personal && deal.Curator == user && contains) ||
                        (type == PermissionDistributionType.Teams && contains))
                    {
                        return(deal);
                    }
                }

                return(null);
            }
        }