Ejemplo n.º 1
0
        private async Task <ReleaseBatch> GetReleaseBatch(string idOrName, bool includeItems, bool includeLogo)
        {
            ReleaseBatch releaseBatch = null;

            IQueryable <ReleaseBatch> query = _context.ReleaseBatches;

            if (includeItems)
            {
                query = query.Include(b => b.Items);
            }

            if (includeLogo)
            {
                query = query.Include(b => b.Logo);
            }

            int id;

            if (int.TryParse(idOrName, out id))
            {
                releaseBatch = await query.SingleOrDefaultAsync(b => b.Id == id);
            }

            return(releaseBatch ?? await query.SingleOrDefaultAsync(b => b.Name == idOrName));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostReleaseBatch([FromBody] ReleaseBatch releaseBatch)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            releaseBatch.UpdateDateTime = DateTimeOffset.Now;
            releaseBatch.UpdateUserName = User.Identity.Name;

            _context.ReleaseBatches.Add(releaseBatch);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (_context.ReleaseBatches.Count(e => e.Id == releaseBatch.Id) > 0)
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("GetReleaseBatch", new { idOrName = releaseBatch.Id }, releaseBatch));
        }
Ejemplo n.º 3
0
        private ObjectResult GetLockedForbiddenUpdateResult(ReleaseBatch releaseBatch)
        {
            var lockedReason = $"Locked by: {releaseBatch.LockUserName}{(!string.IsNullOrEmpty(releaseBatch.LockComment) ? $" ({releaseBatch.LockComment})" : String.Empty)}";

            return(new ObjectResult(lockedReason)
            {
                StatusCode = StatusCodes.Status403Forbidden
            });
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> CopyReleaseBatch([FromRoute] string idOrName, [FromBody] string copyName)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var releaseBatch = await GetReleaseBatch(idOrName, true, true);

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

            var copyReleaseBatch = new ReleaseBatch();

            copyReleaseBatch.Name = copyName;

            copyReleaseBatch.Description = releaseBatch.Description;

            if (releaseBatch.Logo != null)
            {
                copyReleaseBatch.Logo             = new ReleaseBatchLogo();
                copyReleaseBatch.Logo.Content     = releaseBatch.Logo.Content;
                copyReleaseBatch.Logo.ContentType = releaseBatch.Logo.ContentType;
            }

            if (releaseBatch.Items != null)
            {
                copyReleaseBatch.Items = new List <ReleaseBatchItem>();
                foreach (var item in releaseBatch.Items)
                {
                    var copyItem = new ReleaseBatchItem();
                    copyItem.ProjectId      = item.ProjectId;
                    copyItem.ProjectName    = item.ProjectName;
                    copyItem.ProjectSlug    = item.ProjectSlug;
                    copyItem.ReleaseId      = item.ReleaseId;
                    copyItem.ReleaseVersion = item.ReleaseVersion;
                    copyReleaseBatch.Items.Add(copyItem);
                }
            }

            copyReleaseBatch.UpdateDateTime = DateTimeOffset.Now;
            copyReleaseBatch.UpdateUserName = User.Identity.Name;

            _context.ReleaseBatches.Add(copyReleaseBatch);
            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetReleaseBatch", new { idOrName = copyReleaseBatch.Id }, copyReleaseBatch));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutReleaseBatch([FromRoute] string idOrName, [FromBody] ReleaseBatch releaseBatch)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existingReleaseBatch = await GetReleaseBatch(idOrName, false, false);

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

            if (existingReleaseBatch.IsLocked)
            {
                return(GetLockedForbiddenUpdateResult(existingReleaseBatch));
            }

            if (releaseBatch.Name != null)
            {
                existingReleaseBatch.Name = releaseBatch.Name;
            }
            if (releaseBatch.Description != null)
            {
                existingReleaseBatch.Description = releaseBatch.Description;
            }

            existingReleaseBatch.UpdateDateTime = DateTimeOffset.Now;
            existingReleaseBatch.UpdateUserName = User.Identity.Name;

            await _context.SaveChangesAsync();

            return(new NoContentResult());
        }