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 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 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)); } } }