// add new rental - user access: public RentalDTO AddRental(RentalDTO rental) { Rental rentalToAdd = new Rental { PickupDate = rental.pickupDate, EstimatedReturnDate = rental.estimatedReturnDate, ActualReturnDate = rental.actualReturnDate, UserID = rental.userID, VehicleID = rental.vehicleID, Manufacturer = rental.manufacturer, Model = rental.model }; DB.Rentals.Add(rentalToAdd); DB.SaveChanges(); rental.rentalCode = rentalToAdd.RentalCode; return(rental); }
// modify rental - manager access public RentalDTO UpdateRental(RentalDTO rental) { Rental rentalToUpdate = DB.Rentals .Where(r => r.RentalCode == r.RentalCode).SingleOrDefault(); if (rentalToUpdate == null) { return(null); } rentalToUpdate.PickupDate = rental.pickupDate; rentalToUpdate.EstimatedReturnDate = rental.estimatedReturnDate; rentalToUpdate.ActualReturnDate = rental.actualReturnDate; rentalToUpdate.UserID = rental.userID; rentalToUpdate.VehicleID = rental.vehicleID; DB.SaveChanges(); return(rental); }
public HttpResponseMessage AddRental(RentalDTO rental) { try { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorsManager.GetErrors(ModelState))); } RentalDTO addedRental = rentalLogic.AddRental(rental); return(Request.CreateResponse(HttpStatusCode.Created, addedRental)); } catch (Exception ex) { return(Request.CreateErrorResponse( HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMessage(ex))); } }
public HttpResponseMessage UpdateRental(int rentalCode, RentalDTO rental) { try { rental.rentalCode = rentalCode; RentalDTO updatedRental = rentalLogic.UpdateRental(rental); if (updatedRental == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK, updatedRental)); } catch (Exception ex) { return(Request.CreateErrorResponse( HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMessage(ex))); } }