public Task <IApiResult> StartRental(P_OnlyOneID arg) { return(Task.Run(() => { IApiResult hr = new IApiResult(); using (CarRentEntities db = new CarRentEntities()) { try { var leaser = (from l in db.LeaseRecord where l.LeaseID == arg.id && l.Status == 1 select l).SingleOrDefault(); if (leaser == null) { hr.code = StatusCode.failure; hr.message = "Has been rented."; //已经租了 return hr; } var dev = (from d in db.Devices where d.DeviceID == leaser.DeviceID select d).SingleOrDefault(); var user = db.Users.Find(dev.UserID); if (user.MoneyCount < user.ActivationCount) { hr.code = StatusCode.failure; hr.message = "Insufficient balance."; //用户余额不足 return hr; } dev.Status = 1; //Status (1:已租,0:未租) //var leaser = (from lr in db.LeaseRecord where lr.LeaseID == arg.id select lr).Single(); leaser.Status = Mgoo.CarRent.Common.Lib.CarStatus.BeingRented.toInt(); //1 已申请,等待确认,2 正在出租,3出租完成,4已拒绝 leaser.StartTime = DateTime.Now; //db.LeaseRecord.UpdateAsync(l => l.LeaseID==arg.id, l=> new LeaseRecord { Status = 2 }); db.Entry(leaser).State = System.Data.Entity.EntityState.Modified; db.Entry(dev).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); hr.message = "success!"; } catch (Exception ex) { hr.message = ex.Message; hr.code = StatusCode.error; } } return hr; })); }
public ActionResult Edit([Bind(Include = "tp_UserID,active,firstName,secondName,dateOfBirth,pesel,address,city,postalCode,login,password")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Edit([Bind(Include = "tp_carID,active,type,segment,priceGross,priceNet,deposit,brand,model")] Car car) { if (ModelState.IsValid) { db.Entry(car).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(car)); }
public static bool updateUser(User user) { using (CarRentEntities db = new CarRentEntities()) { User currentUser = db.Users.FirstOrDefault(u => u.ID == user.ID); if (currentUser != null) { db.Entry(currentUser).State = System.Data.Entity.EntityState.Detached; int userId = currentUser.UserID; currentUser = user; currentUser.UserID = userId; db.Entry(currentUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); } else { return(false); } } }
public static bool updateRentCar(RentCar rent, RentCar currentRent) { using (CarRentEntities db = new CarRentEntities()) { try { db.Entry(currentRent).State = System.Data.Entity.EntityState.Detached; string CarNumber = currentRent.CarNumber; int userID = currentRent.UserID; currentRent = rent; currentRent.UserID = userID; currentRent.CarNumber = CarNumber; db.Entry(currentRent).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); } catch { return(false); } } }
public static bool updateCarType(CarType carType) { using (CarRentEntities db = new CarRentEntities()) { try { db.CarTypes.Add(carType); db.Entry(carType).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); } catch (Exception e) { 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 static bool deleteCarType(CarType carType) { using (CarRentEntities db = new CarRentEntities()) { try { db.CarTypes.Attach(carType); db.Entry(carType).State = EntityState.Deleted; db.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
public static bool updateCar(CarsForRent carRent) { using (CarRentEntities db = new CarRentEntities()) { try { db.CarsForRents.Add(carRent); db.Entry(carRent).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); } catch { return(false); } } }