private void InitData() { carHistorydata = new CarHistory(Config.ConnectionString); cboHistory.DataSource = carHistorydata.GetCarStatus(); cboHistory.DisplayMember = "Status"; cboHistory.ValueMember = "Id"; }
public IActionResult AddhireConfirmation(int id, string datepicker, string timepicker, string datepicker1, string timepicker1, string drop_off, string pickup_coor) { string[] retCoordinate = drop_off.Split(','); string[] iniCoordinate = pickup_coor.Split(','); DateTime dt = Convert.ToDateTime(datepicker + " " + timepicker); DateTime dt1 = Convert.ToDateTime(datepicker1 + " " + timepicker1); var hireDuration = (dt1 - dt).TotalSeconds; var hirDuration = makeTimeSpan(hireDuration); CarHistory CH = new CarHistory() { HireTime = dt, InitialLatitude = Convert.ToSingle(iniCoordinate[1]), InitialLongitude = Convert.ToSingle(iniCoordinate[0]), ReturnedLatitude = Convert.ToSingle(retCoordinate[1]), ReturnedLongitude = Convert.ToSingle(retCoordinate[0]), Status = 0, ReturnedTime = dt1, UserId = User.FindFirstValue(ClaimTypes.NameIdentifier), CarId = id }; try { _db.CarHistory.Add(CH); _db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("ERROR while saving"); } return(RedirectToAction("Index", "Carhiredetails")); }
public IActionResult HireCarSubmit(int Id, string PickUpTime, string DropOffTime) { Car car = _db.Cars.Where(c => c.Id == Id).FirstOrDefault(); ParkingLot pl = _db.ParkingLots.Where(p => p.Id == car.ParkingLotId).FirstOrDefault(); DateTime pickUpDateTime = DateTime.Parse(PickUpTime); DateTime dropOffDateTime = DateTime.Parse(DropOffTime); TimeSpan duration = dropOffDateTime.Subtract(pickUpDateTime); CarHistory history = new CarHistory() { HireTime = pickUpDateTime, InitialLongitude = pl.Longitude, InitialLatitude = pl.Latitude, ReturnedLongitude = -1, ReturnedLatitude = -1, ReturnedTime = dropOffDateTime, Status = HireStatus.Planned, UserId = User.FindFirstValue(ClaimTypes.NameIdentifier), CarId = car.Id }; _db.CarHistory.Add(history); _db.SaveChanges(); return(View("CarHireConfirmation")); }
/// <summary> /// 添加历史记录 /// </summary> /// <param name="car"></param> /// <param name="result"></param> private void AddCarHistory(Car car, ActionResult result) { if (!string.IsNullOrEmpty(car.ID) && (((ResultInfo)((JsonResult)result).Data).Result)) { //获得最后一条的历史数据 CarHistory carHistory = this.service.CarHistory.GetLastData(car.ID); if (carHistory != null) { if (carHistory.CarWeight == car.CarWeight) { //未修改皮重 不增加历史记录 return; } } CarHistory _CarHistory = new CarHistory(); _CarHistory.BelongTo = car.BelongTo; _CarHistory.Builder = car.Builder; _CarHistory.BuildTime = car.BuildTime; _CarHistory.BuyDate = car.BuyDate; _CarHistory.CarClass = car.CarClass; _CarHistory.CarClassID = car.CarClassID; //_CarHistory.CarClassName = car.CarClassName; _CarHistory.CarID = car.ID; _CarHistory.CarNo = car.CarNo; _CarHistory.CarStatus = car.CarStatus; _CarHistory.CarTypeID = car.CarTypeID; _CarHistory.CarWeight = car.CarWeight; _CarHistory.ChassisID = car.ChassisID; _CarHistory.DriverForCars = car.DriverForCars; _CarHistory.EngineID = car.EngineID; _CarHistory.FacInnerID = car.FacInnerID; _CarHistory.Factory = car.Factory; _CarHistory.GPSStatus = car.GPSStatus; _CarHistory.IsUsed = car.IsUsed; _CarHistory.LastBackTime = car.LastBackTime; _CarHistory.LeaveFacDate = car.LeaveFacDate; _CarHistory.Lifecycle = car.Lifecycle; _CarHistory.MaxCube = car.MaxCube; _CarHistory.Modifier = car.Modifier; _CarHistory.ModifyTime = DateTime.Now; _CarHistory.OilConsume = car.OilConsume; _CarHistory.OrderNum = car.OrderNum; _CarHistory.Owner = car.Owner; _CarHistory.PumpTypeID = car.PumpTypeID; _CarHistory.Remark = car.Remark; _CarHistory.RentCarName = car.RentCarName; _CarHistory.SIM = car.SIM; _CarHistory.StuffWeight = car.StuffWeight; _CarHistory.TerminalID = car.TerminalID; _CarHistory.Version = car.Version; _CarHistory.CompanyID = car.CompanyID; this.service.CarHistory.Add(_CarHistory); } }
public void HireCarSubmit() { Image image = new Image() { Title = "testTitle", Data = Encoding.ASCII.GetBytes(new string('a', 100)) }; _dbContext.Images.Add(image); _dbContext.SaveChanges(); ParkingLot pl = new ParkingLot() { Longitude = 0, Latitude = 0, Address = "testAddress", Description = "testDescription" }; _dbContext.ParkingLots.Add(pl); _dbContext.SaveChanges(); Car car = new Car() { Registration = "testRegistration", Description = "testDescription", Status = CarStatus.Available, NumSeats = 2, ImageId = image.Id, Image = image, ParkingLot = pl, ParkingLotId = pl.Id }; _dbContext.Cars.Add(car); _dbContext.SaveChanges(); string pickUpTime = "01/01/2020 1pm"; string dropOffTime = "02/02/2020 2pm"; var r = _uc.HireCarSubmit(car.Id, pickUpTime, dropOffTime) as ViewResult; CarHistory ch = _dbContext.CarHistory.Where(c => c.CarId == car.Id).FirstOrDefault(); Assert.AreEqual(car.Id, ch.CarId); }
public bool DeleteRefueling(string refuelingId, CarHistory vehicleHistory, Vehicle vehicle) { var refueling = _context.Refulings.Find(refuelingId); if (refueling != null && vehicleHistory != null) { refueling.IsActive = false; _context.Attach(vehicleHistory); _context.Entry(vehicleHistory).Property("IsActive").IsModified = true; _context.Attach(vehicle); _context.Entry(vehicle).Property("Millage").IsModified = true; _context.SaveChanges(); return(true); } return(false); }
public ActionResult Service([Bind(Include = "carHistoryID,Date,Vin,Mile,Source,Comments")] CarHistory carHistory) { if (ModelState.IsValid) { CarHistory carHistoryOne = new CarHistory { Date = carHistory.Date, Vin = carHistory.Vin, Mile = carHistory.Mile, Source = carHistory.Source, Comments = carHistory.Comments, }; db.CarHistory.Add(carHistoryOne); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(carHistory)); }
public bool AddRefueling(Refueling refuelingModelToAdd, string userId, CarHistory carHistory) { if (refuelingModelToAdd is null) { return(false); } else { refuelingModelToAdd.Id = Guid.NewGuid().ToString(); _context.Refulings.Add(refuelingModelToAdd); refuelingModelToAdd.CreatedDateTime = DateTime.Now; carHistory.VehicleId = refuelingModelToAdd.VehicleId; carHistory.RefulingRef = refuelingModelToAdd.Id; _context.CarHistories.Add(carHistory); _context.Vehicles.FirstOrDefault(x => x.Id == refuelingModelToAdd.VehicleId).Millage = refuelingModelToAdd.MeterStatus; _context.SaveChanges(); return(true); } }
private async Task SetCarHistoryAsync(Car car, List <Dealer> dealers, List <CarVinCodeHistory> list) { foreach (var item in list) { var dealer = dealers.Where(x => x.Name.Equals(item.SellerName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (dealer != null) { CarHistory history = new CarHistory() { Price = item.Price, PageUrl = item.PageUrl, CarState = item.CarState.Equals("new", StringComparison.InvariantCultureIgnoreCase) ? CarState.New : CarState.IsStock, DateFirstSeen = item.DateFirstSeen, DateLastSeen = item.DateLastSeen, DateScraped = item.DateScraped, Car = car, Dealer = dealer }; await _dbCarHistory.AddAsync(history); } } ; }
public JsonResult RentConfirmed(BillInfoVM billInfoVM) { CarHistory carHist = new CarHistory(); carHist.StartingDate = Convert.ToDateTime(Session["StartDate"]); carHist.EndingDate = Convert.ToDateTime(Session["EndDate"]); carHist.TransactionDate = DateTime.Today; carHist.CarID = billInfoVM.CarId; carHist.CarStateID = 3; // Rezervasyon durumu: Kirada if (Session["LoginId"] != null) { carHist.CustomerID = billInfoVM.CustomerId; } else { Customer customer = new Customer(); var names = billInfoVM.CustomerName.Split(' '); customer.FirstName = names[0]; customer.LastName = names[1]; customer.Address = billInfoVM.CustomerAddress; customer.DateOfBirth = billInfoVM.CustomerBirth; customer.Email = billInfoVM.CustomerMail; customer.Phone = billInfoVM.CustomerPhone; customer.SocialNumber = billInfoVM.CustomerSocialNum; customer.RoleID = 2; carHist.Customer = customer; } BillInfo billInfo = new BillInfo(); if (billInfoVM.IsPersonalBill) { billInfo.FirstName = billInfoVM.BillFirstName; billInfo.LastName = billInfoVM.BillLastName; billInfo.Address = billInfoVM.BillAddress; billInfo.Country = billInfoVM.BillCountry; } else { billInfo.CompanyName = billInfoVM.BillCompanyName; billInfo.Address = billInfoVM.BillCompanyAddress; billInfo.Country = billInfoVM.BillCompanyCountry; billInfo.TaxNo = billInfoVM.BillTaxNo; billInfo.TaxOffice = billInfoVM.BillTaxOffice; } Bill bill = new Bill(); bill.Date = DateTime.Today; bill.PaymentTypeID = 1; // Ödeme Tipi: Kredi Kartı bill.Price = billInfoVM.TotalPrice; bill.BillInfo = billInfo; carHist.Bills.Add(bill); CarHistoryBussiness _carHistoryBll = new CarHistoryBussiness(); string result; try { _carHistoryBll.Add(carHist); result = "İşleminiz başarıyla tamamlanmıştır."; } catch (Exception ex) { result = string.Format("İşleminiz başarısız. {0}", ex.Message); } return(Json(result)); }