Ejemplo n.º 1
0
        public virtual async Task <IActionResult> Put(Guid id, [FromBody] T value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var result = await repository.UpdateAsync(id, value);

                await unitOfWork.CommitAsync();

                return(Accepted(result));
            }
            catch (SyncConflictVersionException <T> e)
            {
                if (Request.Headers.TryGetValue("ForceConflictUpdate", out StringValues values) && values.Any() && values.First() == bool.TrueString)
                {
                    //TODO : Change with logger
                    Trace.WriteLine($"Conflict handled with ForceConflictUpdate");
                    e.Value.Version = e.Existing.Version;
                    var result = await repository.UpdateAsync(id, value);

                    await unitOfWork.CommitAsync();

                    return(Accepted(result));
                }
                return(StatusCode(StatusCodes.Status409Conflict, e.Existing));
            }
        }
Ejemplo n.º 2
0
        public async Task ProcessSyncJob(SyncJobCompositeModel syncJobCompositeModel)
        {
            try
            {
                await LogInformation("Setting the starting date to UTC Now", syncJobCompositeModel);

                syncJobCompositeModel.SyncModel.Started = DateTime.UtcNow;
                await _syncRepository.UpdateAsync(syncJobCompositeModel.SyncModel);

                var isSuccessful = await SyncAllRecords(syncJobCompositeModel);

                await ProcessStatus(syncJobCompositeModel, isSuccessful);
            }
            catch (Exception ex)
            {
                await LogException($"Exception when processing Sync Job {syncJobCompositeModel.SyncModel.Id} {ex.Message}", syncJobCompositeModel);
            }
        }