// GET: Admin/ManageRent /// <summary> /// all rents /// </summary> /// <returns>view with rents list</returns> public ActionResult Index() { using (RentCar tCar = new RentCar()) { return(View(tCar.GetAll().ToList())); } }
public async Task <bool> Rent(RentCar rentCar, string username) { var user = await this.context.Users.SingleOrDefaultAsync(u => u.UserName == username); var car = await this.context.Cars.SingleOrDefaultAsync(c => c.Id == rentCar.CarId); if (user == null || car == null) { return(false); } rentCar.StartDate = DateTime.Now; rentCar.User = user; var totalDays = (rentCar.EndDate - rentCar.StartDate).Days + 1; rentCar.TotalPrice = totalDays * car.RentPricePerDay; user.Balance -= rentCar.TotalPrice; if (user.Balance < rentCar.TotalPrice) { return(false); } this.context.RentedCars.Add(rentCar); await this.context.SaveChangesAsync(); return(true); }
public ActionResult DeleteConfirmed(long id) { RentCar rentCar = db.RentCars.Find(id); db.RentCars.Remove(rentCar); db.SaveChanges(); return RedirectToAction("Index"); }
public ActionResult Order([ModelBinder(typeof(OrderRentModelBinder))] OrderRentModel obj) { try { using (RentCar rent = new RentCar()) { rent.Create(obj.order); } using (CarM car = new CarM()) { Car updated = car.SearchFor(c => c.CarNumber == obj.order.NumCar).FirstOrDefault(); updated.FreeForRent = false; car.Update(updated); return(RedirectToAction("Success", "Rent")); } } catch (DbUpdateException e) { foreach (var eve in e.Entries) { Console.WriteLine("Entity of type \"{0}\" has the following validation errors:", eve.Entity); } throw; } catch (Exception ex) { return(View(ex)); } }
/// <summary> /// rents list /// </summary> /// <returns></returns> public ActionResult List() { using (RentCar rent = new RentCar()) { return(View(rent.GetList(User.Identity.Name).ToList())); } }
public List <Car> GetAll(Expression <Func <Car, bool> > filter = null) { using (RentCar context = new RentCar()) { return(filter == null?context.Set <Car>().ToList() : context.Set <Car>().Where(filter).ToList()); } }
public Car Get(Expression <Func <Car, bool> > filter) { using (RentCar context = new RentCar()) { return(context.Set <Car>().SingleOrDefault(filter)); } }
public ActionResult Viewcar(int id) { RentCar rtcr = db.RentCars.Where(r => r.RtID == id).FirstOrDefault(); var cars = db.Cars.Include(c => c.RentCar).Where(c => c.RtID == rtcr.RtID); return(View(cars.ToList())); }
public ActionResult CreateRenttOwner(CreateVM create) { if (ModelState.IsValid) { Role rol = new Role(); Credential cred = new Credential(); cred.Email = create._credential.Email; cred.Password = create._credential.Password; cred.RoleID = 5; db.Credentials.Add(cred); db.SaveChanges(); User usr = new User(); usr.Name = create._user.Name; usr.CredID = cred.CredID; db.Users.Add(usr); db.SaveChanges(); RentCar rtcr = new RentCar(); rtcr.RtNm = create._rentcar.RtNm; rtcr.CredID = cred.CredID; rtcr.RtImg = create._rentcar.RtImg; db.RentCars.Add(rtcr); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RoleID = new SelectList(db.Roles, "RoleID", "RoleNm", create._credential.RoleID); return(View(create)); }
public ActionResult DeleteRequest(RentCar car) { var mycar = db.RentCars.Find(car.id); db.RentCars.Remove(mycar); db.SaveChanges(); return(RedirectToAction("getUsercars")); }
// GET: RentBookings public ActionResult Index() { var id = Convert.ToInt32(Session["id"]); RentCar rtcr = db.RentCars.Where(x => x.CredID == id).FirstOrDefault(); var rentBookings = db.RentBookings.Include(r => r.Car).Include(r => r.User).Where(x => x.RtID == rtcr.RtID); return(View(rentBookings.ToList())); }
public void Delete(Car entity) { using (RentCar context = new RentCar()) { var deletedEntity = context.Entry(entity); deletedEntity.State = EntityState.Deleted; context.SaveChanges(); } }
public void Add(Car entity) { using (RentCar context = new RentCar()) { var addedEntity = context.Entry(entity); addedEntity.State = EntityState.Added; context.SaveChanges(); } }
public void Update(Car entity) { using (RentCar context = new RentCar()) { var updatedEntity = context.Entry(entity); updatedEntity.State = EntityState.Modified; context.SaveChanges(); } }
public ActionResult Edit([Bind(Include = "Id,RentStarTime,RentEndTime")] RentCar rentCar) { if (ModelState.IsValid) { db.Entry(rentCar).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(rentCar)); }
public ActionResult EditRequest(RentCar car) { if (ModelState.IsValid) { car.date = DateTime.Now; db.Entry(car).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("getUsercars")); } return(View(car)); }
public ActionResult Edit([Bind(Include = "RtID,CredID,RtNm")] RentCar rentCar) { if (ModelState.IsValid) { db.Entry(rentCar).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.CredID = new SelectList(db.Credentials, "CredID", "Email", rentCar.CredID); return View(rentCar); }
public ActionResult Create([Bind(Include = "RtID,CredID,RtNm")] RentCar rentCar) { if (ModelState.IsValid) { db.RentCars.Add(rentCar); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.CredID = new SelectList(db.Credentials, "CredID", "Email", rentCar.CredID); return View(rentCar); }
// GET: RentCars/Delete/5 public ActionResult Delete(long? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } RentCar rentCar = db.RentCars.Find(id); if (rentCar == null) { return HttpNotFound(); } return View(rentCar); }
// GET: Cars public ActionResult Index() { String role = Session["Role"].ToString(); if (role != "Rent Owner") { return(RedirectToAction("Signin", "Account")); } var id = Convert.ToInt32(Session["id"]); RentCar rtcr = db.RentCars.Where(r => r.CredID == id).FirstOrDefault(); var cars = db.Cars.Include(c => c.RentCar).Where(c => c.RtID == rtcr.RtID); return(View(cars.ToList())); }
// GET: RentCars/Edit/5 public ActionResult Edit(long? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } RentCar rentCar = db.RentCars.Find(id); if (rentCar == null) { return HttpNotFound(); } ViewBag.CredID = new SelectList(db.Credentials, "CredID", "Email", rentCar.CredID); return View(rentCar); }
// GET: RentCars/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RentCar rentCar = db.RentCars.Find(id); if (rentCar == null) { return(HttpNotFound()); } return(View(rentCar)); }
public string Free(int?ID, int?dist) { Car carFree = null; var days = 0.0; JavaScriptSerializer TheSerializer = new JavaScriptSerializer(); using (RentCar rentM = new RentCar()) { // search last active rent by car id CarsRent rent = rentM.SearchFor(c => c.NumCar == ID).LastOrDefault(); if (rent != null) { rent.RealFinishRent = System.DateTime.Now; rentM.Update(rent); days = (rent.FinishRent - rent.StartRent).TotalDays; // search & free-up car using (CarM tCar = new CarM()) { carFree = tCar.SearchFor(c => c.CarNumber == ID).First(); carFree.FreeForRent = true; if (dist != null) { carFree.CurrentDistance = (int)dist; } tCar.Update(carFree); } // succsess response var TheJson = TheSerializer.Serialize(new { ID = carFree.CarNumber, CarModel = carFree.CarModel, Days = days, } ); return(TheJson); } else { // bad response var TheJsonErr = TheSerializer.Serialize(new { text = "Invalid rent detected" } ); return(TheJsonErr); } } }
public ActionResult Index(string IdOrNum) { using (RentCar rents = new RentCar()) { int uid; bool isNumeric = int.TryParse(IdOrNum, out uid); if (isNumeric == true) { return(View(rents.GetByIdOrNum(uid).ToList())); } return(View(rents.GetAll().ToList())); } }
public IHttpActionResult deleteCarOrder(RentCar rent) { bool isCarTypeExists = BLCars.getAllRentCars().Any(c => c.CarNumber == rent.CarNumber); if (isCarTypeExists) { bool isDeleted = BLCars.deleteRentCar(rent); if (isDeleted) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.OK, "Rent car deleted successfully"))); } return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Failed to delete car type"))); } return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Car does not exist"))); }
public static bool addRent(RentCar rent) { using (CarRentEntities db = new CarRentEntities()) { try { db.RentCars.Add(rent); db.SaveChanges(); return(true); } catch { return(false); } } }
public static bool deleteRentCar(RentCar rent) { using (CarRentEntities db = new CarRentEntities()) { try { db.RentCars.Attach(rent); db.Entry(rent).State = EntityState.Deleted; db.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
public string Edit(CarsRent curr) { // serialization instance JavaScriptSerializer TheSerializer = new JavaScriptSerializer(); try { // search rent in data base using (RentCar rent = new RentCar()) { // update CarsRent eqv = rent.GetById(curr.id); if (eqv != null) { eqv.StartRent = curr.StartRent; eqv.FinishRent = curr.FinishRent; eqv.RealFinishRent = curr.RealFinishRent; rent.Update(eqv); } } // response success var TheJson = TheSerializer.Serialize(new { id = curr.id, NumCar = curr.NumCar, NumUser = curr.NumUser, StartRent = curr.StartRent, FinishRent = curr.FinishRent, RealFinishRent = curr.RealFinishRent, } ); return(TheJson); } catch { // bad response var TheJsonErr = TheSerializer.Serialize(new { text = "Invalid operaton..." } ); return(TheJsonErr); } }
public IHttpActionResult addRentOrder(RentCar rent) { bool isRentExist = BLCars.getAllRentCars().Any(c => c.CarNumber == rent.CarNumber); if (!isRentExist) { try { BLCars.addRent(rent); return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.OK, "rent added successfully"))); } catch (Exception e) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Failed to add rent car"))); } } return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "rent car already exist!"))); }
public IHttpActionResult updateCarOrder(RentCar rent) { RentCar currentCar = BLCars.getAllRentCars().FirstOrDefault(c => c.CarNumber == rent.CarNumber); if (currentCar != null) { try { BLCars.updateRentCar(rent, currentCar); return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.OK, "car type updated successfully"))); } catch (Exception e) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Failed to update car"))); } } return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Car does not exist"))); }