Пример #1
0
        public async Task <IActionResult> PutDeveloper([FromRoute] int id, [FromBody] Developer developer)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (id != developer.Id)
                {
                    return(BadRequest());
                }

                _context.Entry(developer).State = EntityState.Modified;

                await _context.SaveChangesAsync();

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

                return(Ok(developer));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> PutPublisher([FromRoute] int id, [FromBody] Publisher publisher)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (id != publisher.Id)
                {
                    return(BadRequest());
                }

                _context.Entry(publisher).State = EntityState.Modified;

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    if (!PublisherExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw ex;
                    }
                }

                return(Ok(publisher));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }