public HttpResponseMessage Put(int id, [FromBody] ticket ticketObj) { try { using (FlightsBookingInfoDatabaseEntities entities = new FlightsBookingInfoDatabaseEntities()) { var entity = entities.tickets.FirstOrDefault(e => e.id == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Ticket with Id" + id.ToString() + "not found")); } else { entity.id = ticketObj.id; entity.fullName = ticketObj.fullName; entity.passportId = ticketObj.passportId; entity.airlinesName = ticketObj.airlinesName; entity.departureCity = ticketObj.departureCity; entity.arrivalCity = ticketObj.arrivalCity; entity.price = ticketObj.price; entity.gender = ticketObj.gender; entity.email = ticketObj.email; entity.phoneNumber = ticketObj.phoneNumber; entity.dateOfBirth = ticketObj.dateOfBirth; entity.photoPath = ticketObj.photoPath; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Put(int id, [FromBody] Userdetail user) { try { using (FlightsBookingInfoDatabaseEntities entities = new FlightsBookingInfoDatabaseEntities()) { var entity = entities.Userdetails.FirstOrDefault(e => e.id == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with Id" + id.ToString() + "not found")); } else { entity.id = user.id; entity.fullName = user.fullName; entity.gender = user.gender; entity.email = user.email; entity.phoneNumber = user.phoneNumber; entity.dateOfBirth = user.dateOfBirth; entity.roleType = user.roleType; entity.userName = user.userName; entity.passowrd = user.passowrd; entity.isActive = user.isActive; entity.photoPath = user.photoPath; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Put(int id, [FromBody] flight flightObj) { try { using (FlightsBookingInfoDatabaseEntities entities = new FlightsBookingInfoDatabaseEntities()) { var entity = entities.flights.FirstOrDefault(e => e.id == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Flight with Id" + id.ToString() + "not found")); } else { entity.id = flightObj.id; entity.fullName = flightObj.fullName; entity.startTime = flightObj.startTime; entity.endTime = flightObj.endTime; entity.passengerCapacity = flightObj.passengerCapacity; entity.departureCity = flightObj.departureCity; entity.arrivalCity = flightObj.arrivalCity; entity.photoPath = flightObj.photoPath; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] ticket ticketObj) { try { using (FlightsBookingInfoDatabaseEntities entities = new FlightsBookingInfoDatabaseEntities()) { entities.tickets.Add(ticketObj); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, ticketObj); message.Headers.Location = new Uri(Request.RequestUri + ticketObj.id.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Delete(int id) { try { using (FlightsBookingInfoDatabaseEntities entities = new FlightsBookingInfoDatabaseEntities()) { var entity = entities.tickets.FirstOrDefault(e => e.id == id); if (entity == null) { return(Request.CreateResponse(HttpStatusCode.OK, entity)); } else { entities.tickets.Remove(entity); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }