public IHttpActionResult PostGig(GigResource gig) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var gigService = new GigService(); if (!gigService.CreateGig(gig)) { return(InternalServerError()); } return(Ok()); }
public bool CreateGig(GigResource gig) { var entity = new Gig() { Date = gig.Date, PostalCode = gig.PostalCode, ArtistId = gig.ArtistId }; using (var context = new OneOffEntities()) { Artist artist = context .Artists .SingleOrDefault(a => a.ArtistId == entity.ArtistId); artist.Gigs.Add(entity); context.Gigs.Add(entity); return(context.SaveChanges() == 1); } }