Exemplo n.º 1
0
        public async Task <IActionResult> PutPackageItem([FromRoute] int id, [FromBody] Package packageItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!packageExists(id))
            {
                return(NotFound());
            }

            var item = _context.Packages.First(pi => pi.ID == id);

            try
            {
                item.Name          = packageItem.Name ?? item.Name;
                item.ArtifactRefID = packageItem.ArtifactRefID ?? item.ArtifactRefID;
                item.Version++;

                _context.Update(item);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(Ok(item));
        }
Exemplo n.º 2
0
        public IActionResult PutLecture([FromRoute] string id, [FromBody] Lecture lecture)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            else if (!lectureExists(id))
            {
                return(NotFound(id));
            }


            var item = _context.Lectures.First(li => li.ID == id);

            try
            {
                item.Name = (lecture.Name != null && lecture.Name != item.Name) ? lecture.Name : item.Name;
                item.Version++;

                _context.Update(item);
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException dbce)
            {
                Tracer.TraceMessage(dbce.Message);
                return(StatusCode(500));
            }

            return(Ok(item));
        }