public async Task <IActionResult> UpdateEvent([FromBody] EventsCatalog eventObj) { if (ModelState.IsValid) { try { if (_context != null) { _context.Events.Update(eventObj); await _context.SaveChangesAsync(); return(Ok()); } return(NotFound()); } catch (Exception ex) { if (ex.GetType().FullName == "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException") { return(NotFound()); } return(BadRequest()); } } else { return(BadRequest()); } }
public async Task <ActionResult <EventsCatalog> > CreateEvent(EventsCatalog eventsCatalog) { try { _context.Events.Add(eventsCatalog); await _context.SaveChangesAsync(); // calling "Events" api with new Event's id to get the Event object return(CreatedAtAction(nameof(Events), new { EventId = eventsCatalog.Id }, eventsCatalog)); } catch (Exception e) { return(BadRequest("Event not created !!!")); } }