Пример #1
0
        public async Task <(Assignment assignment, RepositoryOutcomeAction outcomeAction, object error)> GetAssignmentByIdAsync(string id,
                                                                                                                                bool populateClient = false,
                                                                                                                                bool populateWorker = false,
                                                                                                                                CancellationToken cancellationToken = default(CancellationToken))
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            var result = await _mongoDatabase.Assignments()
                         .Find(x => x.Id == id)
                         .SingleOrDefaultAsync(cancellationToken);

            if (result != null)
            {
                if (populateClient)
                {
                    result.Client = await _mongoDatabase.Clients()
                                    .Find(x => x.Id == result.ClientId)
                                    .SingleOrDefaultAsync(cancellationToken);
                }

                if (populateWorker)
                {
                    result.Worker = await _mongoDatabase.Workers()
                                    .Find(x => x.Id == result.WorkerId)
                                    .SingleOrDefaultAsync(cancellationToken);
                }
            }

            return(result,
                   result == null ? RepositoryOutcomeAction.NotFoundNone : RepositoryOutcomeAction.OkNone,
                   null);
        }
Пример #2
0
 public void EnsureAssignment(Assignment assignment)
 {
     _mongoDatabase.Assignments().InsertOne(assignment);
 }