public virtual async Task <IActionResult> Update(int buildId, [FromBody, Required] BuildUpdate buildUpdate)
        {
            Data.Models.Build build = await _context.Builds.Where(b => b.Id == buildId).FirstOrDefaultAsync();

            if (build == null)
            {
                return(NotFound());
            }

            bool doUpdate = false;

            if (buildUpdate.Released.HasValue && build.Released != buildUpdate.Released.Value)
            {
                build.Released = buildUpdate.Released.Value;
                doUpdate       = true;
            }

            if (doUpdate)
            {
                _context.Builds.Update(build);
                await _context.SaveChangesAsync();
            }

            return(Ok(new Models.Build(build)));
        }
Esempio n. 2
0
 public static Task UpdateDocument <T>(
     this IMongoCollection <T> collection,
     string id,
     BuildUpdate <T> update,
     CancellationToken cancellationToken = default
     ) where T : Document
 => collection.UpdateDocument(id, update, null, cancellationToken);
 public static Task <long> UpdateManyDocuments <T>(
     this IMongoDatabase database,
     BuildFilter <T> filter,
     BuildUpdate <T> update,
     CancellationToken cancellationToken = default
     ) where T : Document
 => database.GetDocumentCollection <T>().UpdateManyDocuments(filter, update, cancellationToken);
 public static Task UpdateDocument <T>(
     this IMongoDatabase database,
     string id,
     BuildUpdate <T> update,
     CancellationToken cancellationToken = default
     ) where T : Document
 => database.GetDocumentCollection <T>().UpdateDocument(id, update, cancellationToken);
Esempio n. 5
0
    public async Task <BuildUpdate> GetUpdatesAsync(string search = "")
    {
        var buildUpdate = await _cacheService.GetOrSetAsync(
            cacheKey : ListUpdatesApi,
            action : async() => {
            var obj = await ListUpdatesApi.OpenFlurlSession()
                      .GetJsonAsync <BuildUpdate>();

            return(obj);
        }
            );

        var filteredBuilds = buildUpdate.Response.Builds
                             .Where(build => build.BuildNumber.Contains(search))
                             .ToList();

        _logger.Debug("Retrieve about {0} build(s)", buildUpdate.Response.Builds.Count);

        var filteredUpdate = new BuildUpdate
        {
            JsonApiVersion = buildUpdate.JsonApiVersion,
            Response       = new Response
            {
                ApiVersion = buildUpdate.Response.ApiVersion,
                Builds     = filteredBuilds
            }
        };

        return(filteredUpdate);
    }
 public static Task UpdateDocument <T>(
     this IMongoDatabase database,
     BuildFilter <T> filter,
     BuildUpdate <T> update,
     Action <UpdateOptions>?configure,
     CancellationToken cancellationToken = default
     ) where T : Document
 => database.GetDocumentCollection <T>().UpdateDocument(filter, update, configure, cancellationToken);
Esempio n. 7
0
 public static Task <long> UpdateManyDocuments <T>(
     this IMongoCollection <T> collection,
     BuildFilter <T> filter,
     BuildUpdate <T> update,
     CancellationToken cancellationToken = default
     ) where T : Document
 => collection.UpdateManyDocuments(
     filter(Builders <T> .Filter),
     update(Builders <T> .Update),
     null,
     cancellationToken
     );
Esempio n. 8
0
 /// <summary>
 /// Updates a document and by default inserts a new one if no matching document by id is found.
 /// </summary>
 public static Task UpdateDocument <T>(
     this IMongoCollection <T> collection,
     string id,
     BuildUpdate <T> update,
     Action <UpdateOptions>?configure,
     CancellationToken cancellationToken = default
     ) where T : Document
 => collection.UpdateDocument(
     id,
     update(Builders <T> .Update),
     configure,
     cancellationToken
     );
Esempio n. 9
0
        public async Task <Build> UpdateAsync(
            BuildUpdate body,
            int buildId,
            CancellationToken cancellationToken = default
            )
        {
            if (body == default(BuildUpdate))
            {
                throw new ArgumentNullException(nameof(body));
            }

            if (buildId == default(int))
            {
                throw new ArgumentNullException(nameof(buildId));
            }

            const string apiVersion = "2019-01-16";

            var _baseUri = Client.Options.BaseUri;
            var _url     = new RequestUriBuilder();

            _url.Reset(_baseUri);
            _url.AppendPath(
                "/api/builds/{buildId}".Replace("{buildId}", Uri.EscapeDataString(Client.Serialize(buildId))),
                false);

            _url.AppendQuery("api-version", Client.Serialize(apiVersion));


            using (var _req = Client.Pipeline.CreateRequest())
            {
                _req.Uri    = _url;
                _req.Method = RequestMethod.Patch;

                if (body != default(BuildUpdate))
                {
                    _req.Content = RequestContent.Create(Encoding.UTF8.GetBytes(Client.Serialize(body)));
                    _req.Headers.Add("Content-Type", "application/json; charset=utf-8");
                }

                using (var _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false))
                {
                    if (_res.Status < 200 || _res.Status >= 300)
                    {
                        await OnUpdateFailed(_req, _res).ConfigureAwait(false);
                    }

                    if (_res.ContentStream == null)
                    {
                        await OnUpdateFailed(_req, _res).ConfigureAwait(false);
                    }

                    using (var _reader = new StreamReader(_res.ContentStream))
                    {
                        var _content = await _reader.ReadToEndAsync().ConfigureAwait(false);

                        var _body = Client.Deserialize <Build>(_content);
                        return(_body);
                    }
                }
            }
        }
Esempio n. 10
0
 protected ValueTask <Operation <T> > UpdateOperationTask(BuildFilter <T> filter, BuildUpdate <T> update)
 => new(UpdateOperation(filter, update));
Esempio n. 11
0
 protected Operation <T> UpdateOperation(BuildFilter <T> filter, BuildUpdate <T> update)
 => new UpdateOperation <T>(filter(Builders <T> .Filter), update(Builders <T> .Update));
Esempio n. 12
0
 /// <summary>
 ///     Update an existing build.
 /// </summary>
 /// <param name="buildId">Build to update</param>
 /// <param name="buildUpdate">Updated build info</param>
 /// <returns>Updated build</returns>
 public Task <Build> UpdateBuildAsync(int buildId, BuildUpdate buildUpdate)
 {
     return(_barClient.Builds.UpdateAsync(buildUpdate, buildId));
 }
Esempio n. 13
0
 public Task <Build> UpdateBuildAsync(int buildId, BuildUpdate buildUpdate)
 {
     throw new NotImplementedException();
 }