public HttpResponseMessage AddVehicle(VehicleDTO vehicle) { try { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorsManager.GetErrors(ModelState))); } VehicleDTO addedVehicle = vehiclesLogic.AddVehicle(vehicle); return(Request.CreateResponse(HttpStatusCode.Created, addedVehicle)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ErrorsManager.GetInnerMessage(ex))); } }
//add car - admin access public VehicleDTO AddVehicle(VehicleDTO vehicle) { // יצירת רכב חדש בדטה בייס Vehicle vehicleToAdd = new Vehicle { VehicleTypeID = vehicle.vehicleTypeID, Mileage = vehicle.mileage, CarImage = vehicle.carImage, RentingProper = true, RentingAvailibility = true, RegistrationNumber = vehicle.registrationNumber, BranchID = vehicle.branchID }; DB.Vehicles.Add(vehicleToAdd); DB.SaveChanges(); vehicle.vehicleID = vehicleToAdd.VehicleID; return(vehicle); }
//edit cars - admin access - don't erase public VehicleDTO UpdateVehicle(VehicleDTO vehicle) { Vehicle vehicleToUpdate = DB.Vehicles .Where(v => v.VehicleID == vehicle.vehicleID).SingleOrDefault(); if (vehicleToUpdate == null) { return(null); } vehicleToUpdate.VehicleTypeID = vehicle.vehicleTypeID; vehicleToUpdate.Mileage = vehicle.mileage; vehicleToUpdate.RentingProper = vehicle.rentingProper; vehicleToUpdate.RentingAvailibility = vehicle.rentingAvailibility; vehicleToUpdate.RegistrationNumber = vehicle.registrationNumber; vehicleToUpdate.BranchID = vehicle.branchID; DB.SaveChanges(); return(vehicle); }
public IHttpActionResult SaveImage(int id) { string fileName = Guid.NewGuid() + ".jpg"; for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++) { var myFile = HttpContext.Current.Request.Files[i]; if (myFile != null && myFile.ContentLength != 0) { string fullPath = HttpContext.Current.Server.MapPath("~/Uploads/" + fileName); myFile.SaveAs(fullPath); } } //save db logic.SaveImage(id, fileName); VehicleDTO car = logic.GetOneVehicle(id); car.carImage = fileName; VehicleDTO update = logic.UpdateVehicle(car); return(Ok()); }