public IActionResult Post([FromBody] Comment comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Comment.Add(comment); try { _context.SaveChanges(); } catch (DbUpdateException) { if (CommentExists(comment.CommentId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(Ok(comment)); }
public IActionResult Post([FromBody] Ticket ticket) //public IActionResult Post(Ticket ticket) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Ticket.Add(ticket); try { _context.SaveChanges(); } catch (DbUpdateException) { if (TicketExists(ticket.TicketId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtRoute("GetTicket", new { id = ticket.TicketId }, ticket)); }
public IActionResult Post([FromBody] Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Customer.Add(customer); try { _context.SaveChanges(); } catch (DbUpdateException) { if (CustomerExists(customer.CustomerId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtRoute("GetCustomer", new { id = customer.CustomerId }, customer)); }
public IActionResult Post([FromBody] Employee employee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existingUser = from e in _context.Employee where e.Username == employee.Username select e; if (existingUser.Count <Employee>() > 0) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } _context.Employee.Add(employee); try { _context.SaveChanges(); } catch (DbUpdateException) { if (EmployeeExists(employee.EmployeeId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtRoute("GetEmployee", new { id = employee.EmployeeId }, employee)); }