private void RuleForUpdate()
 {
     RuleFor(x => x)
     .Must(x =>
     {
         /// NOTE:  null solution check is not quite correct
         /// as this would result in a FK exception if we let it through
         /// but it is good enough for the moment
         var soln = _solutionDatastore.ById(x.Id);
         return(soln != null && x.OrganisationId == soln.OrganisationId);
     })
     .WithMessage("Cannot transfer solutions between organisations");
 }
        protected override TechnicalContact Filter(TechnicalContact input)
        {
            if (_context.HasRole(Roles.Admin) ||
                _context.HasRole(Roles.Buyer))
            {
                return(input);
            }

            // Supplier: only own TechnicalContacts
            var soln = _solutionDatastore.ById(input.SolutionId);

            return(_context.ContextOrganisationId() == soln.OrganisationId ? input : null);
        }
 private void SupplierOwn()
 {
     RuleFor(x => x)
     .Must(x =>
     {
         if (_context.HasRole(Roles.Supplier))
         {
             var soln = _solutionDatastore.ById(x.SolutionId);
             return(_context.ContextOrganisationId() == soln.OrganisationId);
         }
         return(_context.HasRole(Roles.Admin));
     })
     .WithMessage("Supplier can only change own Technical Contacts");
 }
Esempio n. 4
0
        protected override AssessmentMessage Filter(AssessmentMessage input)
        {
            if (_context.HasRole(Roles.Admin))
            {
                return(input);
            }

            if (_context.HasRole(Roles.Buyer))
            {
                // Buyer: no visibility
                return(null);
            }

            // Supplier: only own messages
            var soln = _solutionDatastore.ById(input.SolutionId);

            return(_context.ContextOrganisationId() == soln?.OrganisationId ? input : null);
        }
Esempio n. 5
0
        public SolutionEx BySolution(string solutionId)
        {
            return(GetInternal(() =>
            {
                var retval = new SolutionEx
                {
                    Solution = _solutionDatastore.ById(solutionId),
                    TechnicalContact = _technicalContactDatastore.BySolution(solutionId).ToList(),
                    ClaimedStandard = _claimedStandardDatastore.BySolution(solutionId).ToList(),
                    ClaimedCapability = _claimedCapabilityDatastore.BySolution(solutionId).ToList()
                };
                retval.ClaimedCapabilityStandard = retval
                                                   .ClaimedCapability
                                                   .SelectMany(cc => _claimedCapabilityStandardDatastore.ByClaimedCapability(cc.Id).ToList())
                                                   .ToList();

                return retval;
            }));
        }
 public Solution ById(string id)
 {
     return(_filter.Filter(new[] { _datastore.ById(id) }.AsQueryable()).SingleOrDefault());
 }