public HttpResponseMessage Post(tbl_flights flight) { try { entities.tbl_flights.Add(flight); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, flight)); } catch (Exception) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid details entered")); } }
public HttpResponseMessage Put(int id, [FromBody] tbl_schedules schedules) { DbContextTransaction transaction = entities.Database.BeginTransaction(); try { tbl_schedules updateschedule = entities.tbl_schedules.Find(id); updateschedule.arrival_time = schedules.arrival_time; updateschedule.travel_date = schedules.travel_date; updateschedule.departure_time = schedules.departure_time; updateschedule.duration = schedules.duration; updateschedule.avail_economy_class = schedules.avail_economy_class; updateschedule.avail_business_class = schedules.avail_business_class; updateschedule.avail_first_class = schedules.avail_first_class; updateschedule.avail_premium_class = schedules.avail_premium_class; updateschedule.schedule_status = schedules.schedule_status; entities.SaveChanges(); transaction.Commit(); return(Request.CreateResponse(HttpStatusCode.OK, "Successfully updated")); } catch (Exception) { transaction.Rollback(); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Updation can't be performed")); } }
public IHttpActionResult AddUser(user RegistrationForm) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.users.Add(RegistrationForm); db.SaveChanges(); } catch (Exception ex) { throw ex; } return(Ok(RegistrationForm)); }
public string PostUserImage(int id) { try { var httpRequest = HttpContext.Current.Request; foreach (string file in httpRequest.Files) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created); var postedFile = httpRequest.Files[file]; if (postedFile != null && postedFile.ContentLength > 0) { IList <string> AllowedFileExtensions = new List <string> { ".jpg", ".gif", ".png" }; var ext = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.')); var extension = ext.ToLower(); if (!AllowedFileExtensions.Contains(extension)) { var message = string.Format("Please Upload image of type .jpg,.gif,.png."); return("Invalid File Extension"); } else { var filePath = HttpContext.Current.Server.MapPath("~/Images/" + postedFile.FileName + extension); postedFile.SaveAs(filePath); //Save to DB using (gladiatorEntities db = new gladiatorEntities()) { image image = new image() { imgCaption = httpRequest["ImageCaption"], imgName = postedFile.FileName, UID = id }; db.images.Add(image); db.SaveChanges(); } } } var message1 = string.Format("Image Updated Successfully."); return(message1); } var res = string.Format("Please Upload a image."); return(res); } catch (Exception ex) { var res = string.Format(ex.ToString()); return(res); } }
public HttpResponseMessage Post(tbl_users user) { try { entities.tbl_users.Add(user); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, user)); } catch (Exception) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Username already exists in database")); } }
public HttpResponseMessage Post([FromUri] string username, tbl_passengers passenger) { try { List <sp_getpassengers_Result> result = new List <sp_getpassengers_Result>(); result = entities.sp_getpassengers(username).ToList <sp_getpassengers_Result>(); foreach (var item in result) { if (item.name.ToLower() == passenger.name.ToLower()) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "passenger exists already")); } } entities.tbl_passengers.Add(passenger); entities.SaveChanges(); } catch (Exception) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "passenger can not be added")); } return(Request.CreateResponse(HttpStatusCode.Accepted, passenger)); }
public HttpResponseMessage savePassword(tbl_users n) { tbl_users s = entities.tbl_users.Where(t => t.username == n.username).FirstOrDefault(); if (s == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Data cannot be found")); } else { s.password = n.password; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "1")); } }
public HttpResponseMessage Post(tbl_schedules schedules) { DbContextTransaction transaction = entities.Database.BeginTransaction(); try { entities.tbl_schedules.Add(schedules); entities.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Details not entered properly")); } return(Request.CreateResponse(HttpStatusCode.OK, schedules)); }
public HttpResponseMessage cancelTicket(sp_getBookingHistory_Result tick) { DbContextTransaction transaction = entities.Database.BeginTransaction(); try { tbl_tickets ticket = entities.tbl_tickets.Where(u => u.ticket_id == tick.ticket_id).FirstOrDefault(); ticket.status = "cancelled"; entities.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not cancel the ticket")); } return(Request.CreateResponse(HttpStatusCode.Accepted, "Ticket Cancelled")); }
public HttpResponseMessage addbooking(tbl_booking booking) { DbContextTransaction transaction = entities.Database.BeginTransaction(); try { booking.status = "confirmed"; entities.tbl_booking.Add(booking); entities.SaveChanges(); transaction.Commit(); return(Request.CreateResponse(HttpStatusCode.OK, booking)); } catch (Exception) { transaction.Rollback(); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid data entered")); } }
public IHttpActionResult Caption(image newimg) { gladiatorEntities dbi = new gladiatorEntities(); var captionRow = dbi.images.FirstOrDefault(x => x.UID == newimg.UID); //var crop_current = db.crops.FirstOrDefault(u => u.CID == approval.CID); //var bidder = db.users.FirstOrDefault(u => u.UID == crop_current.UID); if (captionRow != null) { captionRow.imgCaption = newimg.imgCaption; //crop_current.current_bid = approval.bid1; //crop_current.bidder_name = bidder.full_name; dbi.SaveChanges(); } return(Ok()); }
public HttpResponseMessage addticket(tbl_tickets ticket) { DbContextTransaction transaction = entities.Database.BeginTransaction(); try { ticket.status = "upcoming"; ticket.gate = 2; entities.tbl_tickets.Add(ticket); entities.SaveChanges(); transaction.Commit(); return(Request.CreateResponse(HttpStatusCode.OK, ticket)); } catch (Exception) { transaction.Rollback(); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid data entered")); } }
public HttpResponseMessage updateuser(string username, tbl_users user) { DbContextTransaction transaction = entities.Database.BeginTransaction(); try { tbl_users target = entities.tbl_users.Where(u => username == u.username).FirstOrDefault(); target.lastname = user.lastname; target.phone = user.phone; target.dob = user.dob; entities.SaveChanges(); transaction.Commit(); return(Request.CreateResponse(HttpStatusCode.OK, target)); } catch (Exception) { transaction.Rollback(); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "updation can't be perfomed")); } }
public IHttpActionResult AddCrop([FromBody] crop newCrop, int id) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } newCrop.UID = id; db.crops.Add(newCrop); db.SaveChanges(); } catch (Exception ex) { throw ex; } return(Ok(newCrop)); }
public IHttpActionResult AddBid([FromBody] bid newbid, int id) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var uid = db.crops.Where(u => u.CID == id).FirstOrDefault(); db.bids.Add(newbid); newbid.UID = uid.UID; newbid.CID = id; db.SaveChanges(); } catch (Exception ex) { throw ex; } return(Ok(newbid)); }