static async Task <Uri> CreateRentedCarAsync(RentedCar car) { HttpResponseMessage response = await client.PostAsJsonAsync("api/Rentacar", car); response.EnsureSuccessStatusCode(); return(response.Headers.Location); }
public HttpResponseMessage PutRentCar(RentedCar model, [ValueProvider(typeof(HeaderValueProviderFactory <string>))] string sessionKey) { return(this.PerformOperationAndHandleExceptions(() => { var context = this.ContextFactory.Create(); var user = this.LoginUser(sessionKey, context); var car = context.Set <Car>().Find(model.Id); if (car == null) { throw new InvalidOperationException("The car does not exist"); } if (car.IsTaken) { throw new InvalidOperationException("The car is already rented"); } car.IsTaken = true; car.RentedBy = user; car.DropOffDate = model.DropOffDate; car.PickUpDate = model.PickUpDate; TimeSpan timeSpan = (model.PickUpDate - model.DropOffDate); int days = timeSpan.Days; decimal change = user.Amount.Value - (days * car.PricePerDay); user.Amount = change; context.SaveChanges(); var response = this.Request.CreateResponse(HttpStatusCode.NoContent); return response; })); }
public void Update(RentedCar obj) { if (obj != null) { _context.Entry(obj).State = EntityState.Modified; } }
static async Task RunAsync() { client.BaseAddress = new Uri("http://localhost:49310/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { //string i = ""; //Console.WriteLine("Araç güncellemek için (1)"); //i = Console.ReadLine(); //if(i=="1") //{ // //Car car = new Car(); // //Console.Write("Airbag:"); // //car.Airbag =Convert.ToBoolean(Console.ReadLine()); // //Console.WriteLine("BaggageCapacity:"); // //car.BaggageCapacity = Convert.ToInt32(Console.ReadLine()); // //Console.WriteLine("CarModel:"); // //car.CarModel = Console.ReadLine(); // //Console.WriteLine("CarName:"); // //car.CarName=Console.ReadLine(); // //Console.WriteLine("CompanyId:"); // //car.CompanyId = Convert.ToInt32(Console.ReadLine()); // //Console.WriteLine("CurrentKm:"); // //car.CurrentKm = Convert.ToInt32(Console.ReadLine()); // //Console.WriteLine("DailyKmLimit:"); // //car.DailyKmLimit = Convert.ToInt32(Console.ReadLine()); // //Console.WriteLine("DailyPrice:"); // //car.DailyPrice = Convert.ToInt32(Console.ReadLine()); // //Console.WriteLine("DriverLicenseAge:"); // //car.DriverLicenseAge = Convert.ToInt32(Console.ReadLine()); // //Console.WriteLine("MinAge:"); // //car.MinAge = Convert.ToInt32(Console.ReadLine()); // //Console.WriteLine("SeatCount:"); // //car.SeatCount = Convert.ToInt32(Console.ReadLine()); // //var url = await CreateCarAsync(car); // //Console.WriteLine($"Created at {url}"); //} //else if(i=="2") //{ RentedCar car = new RentedCar(); Console.WriteLine("Car Id:"); car.carId = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("New Km:"); car.NewKm = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Price:"); car.Price = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Updating..."); await UpdateRentedCarAsync(car); //} } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadLine(); }
private async Task RentThisCarAsync() { using (UserDialogs.Instance.Loading("Loading")) { RentedCar.IsTermin = IsTermin; RentedCar.ClientName = SelectedClient.Name; RentedCar.CarName = SelectedCar.Name; RentedCar.RentId = App.instance.DashboardViewModel.CurrentRent.Id; if (RentedCar.Cmimi.ID > 0) { RentedCar.CmimiID = RentedCar.Cmimi.ID; } var json = JsonConvert.SerializeObject(RentedCar); var g = json.Remove(1, 7); App.client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json"); HttpContent httpContent = new StringContent(g, Encoding.UTF8, "application/json"); var response = await App.client.PostAsync(App.API_URL_BASE + "rentedcars", httpContent); if (response.IsSuccessStatusCode) { //UserDialogs.Instance.Alert("Vetura u leshua me sukses", "Sukses", "OK"); IsSuccess = true; } else { //UserDialogs.Instance.Alert("Vetura nuk u leshua me sukses", "Error", "OK"); IsSuccess = false; return; } var responseString = await response.Content.ReadAsStringAsync(); RentedCar addedCar = JsonConvert.DeserializeObject <RentedCar>(responseString); SelectedRentedCar = addedCar; IsSuccessfullRent = addedCar != null ? true : false; var page = new PostRentedCarPage(); page.BindingContext = this; App.instance.DashboardViewModel.LatestTransactions?.Add(addedCar); var car = App.instance.DashboardViewModel.AvailableCars.FirstOrDefault(x => x.Id == addedCar.CarId); car.Statusi = Car.StatusTypes.Zene; App.instance.DashboardViewModel.AvailableCars.Remove(car); if (App.instance.DashboardViewModel.TakenCars.Count == 0) { App.instance.DashboardViewModel.TakenCars = new ObservableCollection <Car>(); } App.instance.DashboardViewModel.TakenCars.Add(car); if (App.instance.DashboardViewModel.LatestTransactions.Count > 5) { App.instance.DashboardViewModel.LatestTransactions.RemoveAt(0); } App.instance.DashboardViewModel.RentedCarsByRentId?.Add(addedCar); App.instance.DashboardViewModel.PropertyChangedList(); App.instance.DashboardViewModel.LatestTransactionsOnGoing.Add(addedCar); await Task.Delay(100); IsSuccess = true; App.instance.ChangeDetailPage(page); } }
static async Task <RentedCar> UpdateRentedCarAsync(RentedCar car) { HttpResponseMessage response = await client.PutAsJsonAsync("api/Rentacar", car); response.EnsureSuccessStatusCode(); car = await response.Content.ReadAsAsync <RentedCar>(); return(car); }
public bool Insert(RentedCar car) { try { using (var u = new RentedCarBusiness()) { return(u.Insert(car)); } } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
public bool Insert(RentedCar rentedCar) { try { using (var r = new RentedCarRepository()) { r.Insert(rentedCar); r.Save(); return(true); } } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
private void addRentToolStripMenuItem_Click(object sender, EventArgs e) { var rentedCar = new RentedCar(); _formRentedCar.RentedCar = rentedCar; if (_formRentedCar.ShowDialog() == DialogResult.OK) { try { _RentService.AddRentedCar(rentedCar); } catch (Exception exception) { MessageBox.Show(exception.Message); } } }
public RentACarViewModel(ObservableCollection <Client> Clients) { if (Clients == null) { } else { this.Clients = Clients; } GoToRentedCarDetailsCommand = new Command(async() => await GoToRentedCarDetailsAsync()); RentThisCarCommand = new Command(async() => await RentThisCarAsync()); RentedCar = new RentedCar(); RentedCar.KohaELeshimit = DateTime.Today; RentedCar.KohaEKthimit = RentedCar.KohaELeshimit.AddDays(1); GeneratePdfCommand = new Command(async() => await GeneratePdfAsync()); GoToDashboardCommand = new Command(async() => await GoToDashboardAsync()); }
public IHttpActionResult Put([FromBody] RentedCar car) { try { using (var c = new RentedCarBusiness()) { if (c.Update(car)) { return(Ok()); } return(NotFound()); } } catch (Exception ex) { return(BadRequest($"{ex}")); } }
private void listViewRentedCars_SelectedIndexChanged(object sender, EventArgs e) { if (listViewRentedCars.SelectedItems.Count > 0) { rentedCarID = Convert.ToInt32(listViewRentedCars.SelectedItems[0].SubItems[0].Text); btnAdd.Text = "Modify"; RentedCar rentedCar = rh.GetRentedCar(rentedCarID); comboCar.SelectedItem = rentedCar.car; dateTimePickerStartDay.Value = rentedCar.startDate; dateTimePickerEndDay.Value = rentedCar.endDate; checkBoxInsurance.Checked = rentedCar.IsInsured; } else { rentedCarID = 0; btnAdd.Text = "Add"; } }
public void CheckErrors(RentedCar rentedCar) { string errors = ""; if (rentedCar.startDate < DateTime.Now) { errors += "The start date cannot is in the past, please revise your input data regarding this rented car. \n"; } if (rentedCar.endDate.Month - DateTime.Now.Month > 18) { errors += "The car is rented for more than 18 months. It is customer policy we don't give out cars for more than 18 months.\n"; } if (this.IsCarAlreadyRented(rentedCar)) { errors += "The car you chose is already rented for that day."; } if (errors.Length > 0) { throw new ArgumentException(errors); } }
private void btnAdd_Click(object sender, EventArgs e) { int dealID = Convert.ToInt32(listViewDeals.SelectedItems[0].SubItems[0].Text); Deal deal = rh.GetDeal(dealID); Car car = (Car)comboCar.SelectedItem; DateTime startDate = dateTimePickerStartDay.Value; DateTime endDate = dateTimePickerEndDay.Value; bool isInsured = checkBoxInsurance.Checked; RentedCar rentedCar = new RentedCar(car, deal, startDate, endDate, isInsured); if (rentedCarID == 0) { try { rh.SetRentedCarWithCheck(rentedCar); GetRentedCars(); } catch (ArgumentException ex) { MessageBox.Show(ex.Message); } } else { try { rentedCar.rentedCarID = rentedCarID; rh.UpdateRentedCarWithCheck(rentedCar); GetRentedCars(); } catch (ArgumentException ex) { MessageBox.Show(ex.Message); } } }
public void UpdateRentedCarWithCheck(RentedCar rentedCar) { CheckErrors(rentedCar); this.UpdateRentedCar(rentedCar); }
public void SetRentedCarWithCheck(RentedCar rentedCar) { CheckErrors(rentedCar); this.SetRentedCar(rentedCar); }
private async Task KtheVeturenAsync() { using (UserDialogs.Instance.Loading("Loading")) { CurrentRentedCar.KohaAktualeEKthimit = DateTime.Now; var json = JsonConvert.SerializeObject(CurrentRentedCar); App.client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json"); HttpContent httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var response = await App.client.PutAsync(App.API_URL_BASE + "rentedcars/update", httpContent); if (response.IsSuccessStatusCode) { //UserDialogs.Instance.Alert("Vetura u kthye me sukses", "Sukses", "OK"); } else { //UserDialogs.Instance.Alert("Vetura nuk u kthye me sukses", "Error", "OK"); IsSuccess = false; return; } var responseString = await response.Content.ReadAsStringAsync(); RentedCar addedCar = JsonConvert.DeserializeObject <RentedCar>(responseString); IsSuccessfullRent = addedCar != null ? true : false; var page = new PostRentedCarPage(); page.BindingContext = this; IsSuccess = true; var car = TakenCars.FirstOrDefault(x => x.Id == addedCar.CarId); LatestTransactionsFinished.Add(addedCar); LatestTransactionsOnGoing.Remove(addedCar); if (LatestTransactionsFinished.Count > 5) { App.instance.DashboardViewModel.LatestTransactions.RemoveAt(0); } RentedCarsByRentId.Remove(CurrentRentedCar); RentedCarsByRentId.Add(addedCar); var teHyrat = RentedCarsByRentId.ToList().FindAll(x => x.IsFinished && x.KohaELeshimit >= DateTime.Now.AddMonths(-1)); decimal count = 0.00m; foreach (var item in teHyrat) { count += (decimal)item.DitetELeshimit * item.CmimiDitor; } TeHyrat = count; OnPropertyChanged("TeHyrat"); car.Statusi = Car.StatusTypes.Aktiv; car.Km = CurrentRentedCar.KilometrazhiAktual; AvailableCars.Add(car); TakenCars.Remove(car); var ongoing = LatestTransactionsOnGoing.FirstOrDefault(x => x.Id == addedCar.Id); if (ongoing != null) { LatestTransactionsOnGoing.Remove(ongoing); } OnPropertyChanged("LatestTransactionsOnGoing"); HasTakenCars = TakenCars.Any(); HasAvailableCars = AvailableCars.Any(); OnPropertyChanged("HasTakenCars"); await Task.Delay(500); App.instance.ChangeDetailPage(page); } }
static async Task RunAsync() { client.BaseAddress = new Uri("http://localhost:49310/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { string i = ""; Console.WriteLine("Yeni araç eklemek için (1)\nAraç kiralamak için (2)\n"); i = Console.ReadLine(); if (i == "1") { Car car = new Car(); Console.Write("Airbag:"); car.Airbag = Convert.ToBoolean(Console.ReadLine()); Console.WriteLine("BaggageCapacity:"); car.BaggageCapacity = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("CarModel:"); car.CarModel = Console.ReadLine(); Console.WriteLine("CarName:"); car.CarName = Console.ReadLine(); Console.WriteLine("CompanyId:"); car.CompanyId = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("CurrentKm:"); car.CurrentKm = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("DailyKmLimit:"); car.DailyKmLimit = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("DailyPrice:"); car.DailyPrice = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("DriverLicenseAge:"); car.DriverLicenseAge = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("MinAge:"); car.MinAge = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("SeatCount:"); car.SeatCount = Convert.ToInt32(Console.ReadLine()); var url = await CreateCarAsync(car); Console.WriteLine($"Created at {url}"); } else if (i == "2") { RentedCar car = new RentedCar(); Console.WriteLine("Car Id:"); car.carId = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("CustomerName:"); car.CustomerName = Console.ReadLine(); Console.WriteLine("CustomerSurname:"); car.CustomerSurname = Console.ReadLine(); Console.WriteLine("CustomerTC:"); car.CustomerTC = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("DeliveryDate:"); car.DeliveryDate = Convert.ToDateTime(Console.ReadLine()); Console.WriteLine("RentDate:"); car.RentDate = Convert.ToDateTime(Console.ReadLine()); var url = await CreateRentedCarAsync(car); Console.WriteLine($"Created at {url}"); } } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadLine(); }
public UserControlRentedCar(RentedCar rentedCar) { InitializeComponent(); RentedCar = rentedCar; }
public void Insert(RentedCar obj) { _context.RentedCars.Add(obj); }