public HttpResponseMessage Post([FromBody] PointFee pointFee) { using (PointDBEntities entities = new PointDBEntities()) { try { Semester semester = entities.Semesters.FirstOrDefault(s => s.SemesterID == pointFee.SemesterID); if (semester != null) { entities.PointFees.Add(pointFee); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, pointFee); message.Headers.Location = new Uri(Request.RequestUri + pointFee.FeeID.ToString()); return(message); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Semester SemesterID = " + pointFee.SemesterID.ToString() + " does not exist ")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } } }
public HttpResponseMessage Delete(int FeeID) { try { using (PointDBEntities entities = new PointDBEntities()) { entities.Configuration.ProxyCreationEnabled = false; var entity = entities.PointFees.FirstOrDefault(pf => pf.FeeID == FeeID); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "PointFee with FeeID = " + FeeID.ToString() + " not found to delete")); } else { entities.PointFees.Remove(entity); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] Route route) { try { using (PointDBEntities entities = new PointDBEntities()) { Point point = entities.Points.FirstOrDefault(p => p.PointID == route.PointID); if (point != null) { entities.Routes.Add(route); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, route); message.Headers.Location = new Uri(Request.RequestUri + route.RouteID.ToString()); return(message); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Point PointID = " + route.PointID.ToString() + " does not exist ")); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Delete(int PaymentID) { try { using (PointDBEntities entities = new PointDBEntities()) { var entity = entities.PointPayments.FirstOrDefault(pay => pay.PaymentID == PaymentID); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "PointPayment with PaymentID = " + PaymentID.ToString() + " not found to delete")); } else { entities.PointPayments.Remove(entity); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Put(string CNIC, [FromBody] Driver driver) { try { using (PointDBEntities entities = new PointDBEntities()) { var entity = entities.Drivers.FirstOrDefault(d => d.CNIC == CNIC); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Driver with CNIC " + CNIC + " not found to update")); } else { if (entity.CNIC == driver.CNIC) { entity.DriverName = driver.DriverName; entity.ContactNumber = driver.ContactNumber; } else { entities.Drivers.Remove(entity); entities.Drivers.Add(driver); } entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, driver)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] Point point) { using (PointDBEntities entities = new PointDBEntities()) { try { Driver driver = entities.Drivers.FirstOrDefault(d => d.CNIC == point.CNIC); if (driver != null) { entities.Points.Add(point); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, point); message.Headers.Location = new Uri(Request.RequestUri + point.PointID.ToString()); return(message); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Driver CNIC = " + point.CNIC + " does not exist ")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } } }
public HttpResponseMessage Delete(string CNIC) { try { using (PointDBEntities entities = new PointDBEntities()) { var entity = entities.Drivers.FirstOrDefault(d => d.CNIC == CNIC); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Driver with CNIC = " + CNIC + " not found to delete")); } else { entities.Drivers.Remove(entity); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Delete(int SPID) { try { using (PointDBEntities entities = new PointDBEntities()) { entities.Configuration.ProxyCreationEnabled = false; var entity = entities.StudentPoints.FirstOrDefault(sp => sp.StudentPointId == SPID); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "StudentPoint with StudentPointId = " + SPID.ToString() + " not found to delete")); } else { if (entity.PointID != null) { Point point = entities.Points.FirstOrDefault(p => p.PointID == entity.PointID); point.NumberOfSeats = point.NumberOfSeats + 1; entities.StudentPoints.Remove(entity); entities.SaveChanges(); } else { entities.StudentPoints.Remove(entity); entities.SaveChanges(); } return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Put(int SPID, [FromBody] StudentPoint studentPoint) { try { using (PointDBEntities entities = new PointDBEntities()) { var entity = entities.StudentPoints.FirstOrDefault(sp => sp.StudentPointId == SPID); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "StudentPoint with StudentPointId = " + SPID.ToString() + " not found to update")); } else { Point point = entities.Points.FirstOrDefault(p => p.PointID == studentPoint.PointID); if (point != null) { if (point.NumberOfSeats > 0) { point.NumberOfSeats = (entity.PointID == point.PointID ? point.NumberOfSeats : point.NumberOfSeats - 1); studentPoint.StudentPointId = entity.StudentPointId; entity.PickUpAddress = studentPoint.PickUpAddress; entity.PointID = studentPoint.PointID; entity.SemesterID = studentPoint.SemesterID; entity.StudentID = studentPoint.StudentID; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, studentPoint)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No Seats Available")); } } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "PointID = " + studentPoint.PointID.ToString() + " Does not Exist ")); } } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Put(int PaymentID, [FromBody] PointPayment pointPayment) { try { using (PointDBEntities entities = new PointDBEntities()) { var entity = entities.PointPayments.FirstOrDefault(pay => pay.PaymentID == PaymentID); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "PointPayment with PaymentID " + PaymentID.ToString() + " not found to update")); } else { PointFee pointFee = entities.PointFees.FirstOrDefault(pf => pf.FeeID == pointPayment.FeeID); if (pointFee == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "FeeID = " + pointPayment.FeeID.ToString() + " does not exist ")); } else { int NumberOfDaysLate = Convert.ToInt32((pointPayment.DepositDate - pointFee.DueDate).TotalDays); int TotalPayable = pointFee.TransportFee + NumberOfDaysLate * pointFee.FineCharges; entity.FeeID = pointFee.FeeID; entity.StudentID = pointPayment.StudentID; entity.NumberofDaysLate = NumberOfDaysLate; entity.DepositDate = pointPayment.DepositDate; entity.TotalPayable = TotalPayable; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] Driver driver) { using (PointDBEntities entities = new PointDBEntities()) { try { entities.Drivers.Add(driver); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, driver); message.Headers.Location = new Uri(Request.RequestUri + driver.CNIC); return(message); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } } }
public HttpResponseMessage Put(int FeeID, [FromBody] PointFee pointFee) { try { using (PointDBEntities entities = new PointDBEntities()) { var entity = entities.PointFees.FirstOrDefault(pf => pf.FeeID == FeeID); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "PointFee with FeeID " + FeeID.ToString() + " not found to update")); } else { Semester semester = entities.Semesters.FirstOrDefault(s => s.SemesterID == pointFee.SemesterID); if (semester != null) { pointFee.FeeID = entity.FeeID; entity.DueDate = pointFee.DueDate; entity.FineCharges = pointFee.FineCharges; entity.TransportFee = pointFee.TransportFee; entity.SemesterID = pointFee.SemesterID; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, pointFee)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Semester SemesterID = " + pointFee.SemesterID.ToString() + " does not exist ")); } } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] PointPayment pointPayment) { using (PointDBEntities entities = new PointDBEntities()) { try { PointFee pointFee = entities.PointFees.FirstOrDefault(pf => pf.FeeID == pointPayment.FeeID); if (pointFee != null) { int NumberOfDaysLate = Convert.ToInt32((pointPayment.DepositDate - pointFee.DueDate).TotalDays); int TotalPayable = pointFee.TransportFee + NumberOfDaysLate * pointFee.FineCharges; PointPayment p = new PointPayment() { StudentID = pointPayment.StudentID, DepositDate = pointPayment.DepositDate, NumberofDaysLate = NumberOfDaysLate, TotalPayable = TotalPayable, FeeID = pointFee.FeeID }; entities.PointPayments.Add(p); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, p); message.Headers.Location = new Uri(Request.RequestUri + p.PaymentID.ToString()); return(message); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Point Fee FeeID = " + pointPayment.FeeID.ToString() + " does not exist ")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } } }
public HttpResponseMessage Put(int RouteID, [FromBody] Route route) { try { using (PointDBEntities entities = new PointDBEntities()) { var entity = entities.Routes.FirstOrDefault(r => r.RouteID == RouteID); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Route with RouteID " + RouteID.ToString() + " not found to update")); } else { Point point = entities.Points.FirstOrDefault(p => p.PointID == route.PointID); if (point != null) { entity.PointID = route.PointID; entity.RouteStop = route.RouteStop; entity.RouteTime = route.RouteTime; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Point PointID = " + route.PointID.ToString() + " does not exist ")); } } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Put(int PointID, [FromBody] Point point) { try { using (PointDBEntities entities = new PointDBEntities()) { var entity = entities.Points.FirstOrDefault(p => p.PointID == PointID); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Point with PointID " + PointID.ToString() + " not found to update")); } else { Driver driver = entities.Drivers.FirstOrDefault(d => d.CNIC == point.CNIC); if (driver != null) { entity.NumberPlate = point.NumberPlate; entity.NumberOfSeats = point.NumberOfSeats; entity.CNIC = point.CNIC; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Driver CNIC = " + point.CNIC + " Does Not Exist")); } } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] StudentPoint studentPoint) { using (PointDBEntities entities = new PointDBEntities()) { try { Point point = entities.Points.FirstOrDefault(p => p.PointID == studentPoint.PointID); if (point != null) { if (point.NumberOfSeats > 0) { entities.StudentPoints.Add(studentPoint); point.NumberOfSeats = point.NumberOfSeats - 1; entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, studentPoint); message.Headers.Location = new Uri(Request.RequestUri + studentPoint.StudentPointId.ToString()); return(message); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No Seats Available")); } } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "PointID = " + studentPoint.PointID.ToString() + " Does not Exist ")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } } }