private IQueryable <Branch> GetBranchQuery(ScopeOptions scope)
        {
            var query = from branch in ScopeQuery.GetBranchEntityQuery(_context, scope)
                        select new Branch()
            {
                Id             = branch.Id,
                OrganisationId = branch.OrganisationId,
                Name           = branch.Name
            };

            return(query);
        }
        public async Task <List <BranchSimple> > GetBranchesSimple(ScopeOptions scope)
        {
            var query = from branch in ScopeQuery.GetBranchEntityQuery(_context, scope)
                        orderby branch.Name
                        select new BranchSimple()
            {
                Id   = branch.Id,
                Name = branch.Name
            };

            return(await query.ToListAsync());
        }
示例#3
0
        public static IRuleBuilderOptions <T, Guid?> BranchMustBeInScope <T>(this IRuleBuilder <T, Guid?> ruleBuilder, DataContext dataContext, ScopeOptions scope)
        {
            return(ruleBuilder.MustAsync(async(root, branchId, context) =>
            {
                if (!branchId.HasValue)
                {
                    return false;
                }

                var branch = await ScopeQuery.GetBranchEntityQuery(dataContext, scope).FirstOrDefaultAsync(b => b.Id == branchId);

                return branch != null;
            })
                   .WithMessage((root, branchId) =>
            {
                if (!branchId.HasValue)
                {
                    return NOT_EMPTY_MESSAGE;
                }
                return DOESNT_EXIST_MESSAGE;
            })
                   .WithName("Branch"));
        }
        public async Task <Result> UpdateBranch(ScopeOptions scope, Branch branch)
        {
            var validator = new BranchValidator(_context, scope, false);
            var result    = validator.Validate(branch).GetResult();

            if (!result.Success)
            {
                return(result);
            }

            var entity = await ScopeQuery.GetBranchEntityQuery(_context, scope).FirstOrDefaultAsync(b => b.Id == branch.Id);

            if (entity == null)
            {
                return(new Result());
            }

            entity = MapModelToEntity(branch, entity);
            await _context.SaveChangesAsync();

            await _auditService.InsertAuditLog(scope, AuditLog.ACTION_UPDATE, "Branch", entity.Id, branch);

            return(result);
        }