Exemple #1
0
        public async Task <Worker> AddOrUpdateWorker(Guid id)
        {
            var utcNow = DateTime.UtcNow;

            var dbWorker = await this._dbContext.Workers.FirstOrDefaultAsync(w => w.Id == id).ConfigureAwait(false);

            if (dbWorker == null)
            {
                dbWorker = new DbWorker
                {
                    Id      = id,
                    Created = utcNow,
                    Updated = utcNow,
                };

                this._dbContext.Add(dbWorker);
            }

            dbWorker.Updated = utcNow;

            await this._dbContext.SaveChangesAsync().ConfigureAwait(false);

            return(MapWorker(dbWorker));
        }
Exemple #2
0
 private static Worker MapWorker(DbWorker dbWorker) => new Worker
 {
     Id      = dbWorker.Id,
     Created = dbWorker.Created,
     Updated = dbWorker.Updated
 };