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);
        }
        public async Task <Result> InsertBranch(ScopeOptions scope, Branch branch)
        {
            var validator = new BranchValidator(_context, scope, true);
            var result    = validator.Validate(branch).GetResult();

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

            var entity = MapModelToEntity(branch);

            entity.OrganisationId = branch.OrganisationId.Value;
            await _context.Branch.AddAsync(entity);

            await _context.SaveChangesAsync();

            branch.Id  = entity.Id;
            result.Tag = branch;

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

            return(result);
        }