コード例 #1
0
        public async Task <IActionResult> PostAuthorContact([FromBody] AuthorContact authorContact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.AuthorContact.Add(authorContact);
            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (AuthorContactExists(authorContact.Id))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetAuthorContact", new { id = authorContact.Id }, authorContact));
        }
コード例 #2
0
        public async Task <IActionResult> PutAuthorContact([FromRoute] long id, [FromBody] AuthorContact authorContact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AuthorContactExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutAuthorContact(long id, AuthorContact authorContact)
        {
            if (id != authorContact.AuthorId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #4
0
        public void AddContactForAuthor(Guid authorId, AuthorContact contact)
        {
            var author = GetAuthor(authorId);

            if (author != null)
            {
                // if there isn't an id filled out (ie: we're not upserting),
                // we should generate one
                if (contact.Id == Guid.Empty)
                {
                    contact.Id = Guid.NewGuid();
                }
                author.Contacts.Add(contact);
            }
        }
        public async Task <ActionResult <AuthorContact> > PostAuthorContact(AuthorContact authorContact)
        {
            _context.AuthorContact.Add(authorContact);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (AuthorContactExists(authorContact.AuthorId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetAuthorContact", new { id = authorContact.AuthorId }, authorContact));
        }
コード例 #6
0
 public void DeleteContact(AuthorContact contact)
 {
     _context.AuthorsContact.Remove(contact);
 }
コード例 #7
0
 public void UpdateContactForAuthor(AuthorContact contact)
 {
     _context.AuthorsContact.Update(contact);
 }