Пример #1
0
        private ClientContract GetById(short id, User user, Permission permission)
        {
            var type = user.GetPermissionDistributionType(permission);

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

                if (type == PermissionDistributionType.All)
                {
                    return(contract);
                }
                else
                {
                    // один договор может быть связан с несколькими сделками
                    var dealsByContract = clientContractRepository.GetDeals(contract).Select(x => x.Id);

                    var deals    = user.Teams.SelectMany(x => x.Deals).Where(x => dealsByContract.Contains(x.Id));
                    var contains = (deals.Count() > 0);

                    if ((type == PermissionDistributionType.Personal && deals.Any(x => x.Curator == user) && contains) ||
                        (type == PermissionDistributionType.Teams && contains))
                    {
                        return(contract);
                    }
                }

                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// Расчет суммы текущих взаиморасчетов за наличный расчет по договору
        /// </summary>
        /// <param name="clientContract">Договор с клиентом.</param>
        public decimal CalculateClientContractCashPaymentSum(ClientContract clientContract)
        {
            decimal totalCashPaymentSum = 0;

            var deals = clientContractRepository.GetDeals(clientContract);

            foreach (var deal in deals)
            {
                totalCashPaymentSum += deal.CashDealPaymentSum;
            }

            return(totalCashPaymentSum);
        }