public async Task RentCar() { try { if (StartDate.Date < DateTime.Now.Date) { await Application.Current.MainPage.DisplayAlert("Error", "You cannot book before today", "Try again"); return; } if (StartDate.Date == EndDate.Date || EndDate.Date <= StartDate.Date) { await Application.Current.MainPage.DisplayAlert("Error", "The scope of booking period must be at least 1 day and the end date must be greater than the start date.", "Try again"); return; } var search = new BookingSearchRequest { VehicleID = Vehicle.VehicleId }; var listBooking = await _serviceBooking.Get <List <Data.Model.Booking> >(search); foreach (var item in listBooking) { if (item.EndDate.Date > DateTime.Now.Date) // VIDJET !!!! { await Application.Current.MainPage.DisplayAlert("Error", "The vehicle is already reserved. After the reservation expires, you can reserve the vehicle again", "Try again"); return; } } var request = new BookingUpsert { CustomerId = APIService.CustomerId, StartDate = StartDate.Date, EndDate = EndDate.Date, VehicleId = Vehicle.VehicleId, RatingStatus = false, CommentStatus = false }; await _serviceBooking.Insert <Data.Model.Booking>(request); var days = (request.EndDate.Date - request.StartDate.Date).TotalDays; var total = Vehicle.DailyPrice * days; var message = string.Format("Successfully! Total price for {0} days of reservation cost {1} KM.", days, total); await Application.Current.MainPage.DisplayAlert("Message", message, "OK"); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", "Somethning went wrong", "Try again"); } }
public async Task SetNewRating() { if (Mark <= 0 || Mark > 10) { await Application.Current.MainPage.DisplayAlert("Error", "You have to add mark in range 1 - 10!", "OK"); return; } try { var customerID = await _serviceCustomer.GetById <Data.Model.Customer>(APIService.CustomerId); customer = customerID; var car = await _serviceVehicle.GetById <Data.Model.Vehicle>(vehicle.VehicleId); bool answer = await Application.Current.MainPage.DisplayAlert("Alert", "Would you like to add rating?", "Yes", "No"); if (answer) { var request = new RatingUpsert { CustomerId = APIService.CustomerId, VehicleId = vehicle.VehicleId, RatingValue = Mark, RatingDate = DateTime.Now.Date }; var listRatings = await _serviceRating.Get <List <Data.Model.Rating> >(new RatingSearchRequest { CustomerID = customer.CustomerId, VehicleId = vehicle.VehicleId }); foreach (var rat in listRatings) { rat.RatingDate = rat.RatingDate.AddHours(8); if (RatingDate.Date == rat.RatingDate.Date) { await Application.Current.MainPage.DisplayAlert("Message", "Rating for this reservation already exist! You can add just 1 rating for reservation", "Try again"); return; } } request.RatingDate = DateTime.Now.Date; await _serviceRating.Insert <Data.Model.Rating>(request); await Application.Current.MainPage.DisplayAlert("Message", "Successfully! You added your mark for rented car!", "OK"); var listBooking = await _serviceBooking.Get <List <Data.Model.Booking> >(new BookingSearchRequest { CustomerID = customer.CustomerId }); foreach (var item in listBooking) { if (item.VehicleId == car.VehicleId && item.CustomerId == customer.CustomerId) { if (item.RatingStatus == false) { var req = new BookingUpsert { CustomerId = item.CustomerId, VehicleId = item.VehicleId, StartDate = item.StartDate, EndDate = item.EndDate, RatingStatus = true, CommentStatus = item.CommentStatus }; await _serviceBooking.Update <Data.Model.Booking>(item.BookingId, req); return; } } } } } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", "Somethning went wrong", "Try again"); } }
public async Task SetComment() { if (string.IsNullOrEmpty(Description)) { await Application.Current.MainPage.DisplayAlert("Error", "All fields are required", "Try again"); return; } try { var customerID = await _serviceCustomer.GetById <Data.Model.Customer>(APIService.CustomerId); customer = customerID; var car = await _serviceVehicle.GetById <Data.Model.Vehicle>(vehicle.VehicleId); bool answer = await Application.Current.MainPage.DisplayAlert("Alert", "Would you like to leave a comment?", "Yes", "No"); if (answer) { var request = new CommentUpsert { CustomerId = APIService.CustomerId, VehicleId = vehicle.VehicleId, DateOfComment = DateTime.Now.Date, Description = Description, CommentStatus = true }; var listComment = await _serviceComment.Get <List <Data.Model.Comment> >(new CommentSearchRequest { CustomerID = request.CustomerId, VehicleId = request.VehicleId }); foreach (var com in listComment) { com.DateOfComment = com.DateOfComment.AddHours(8); if (CommentDate.Date == com.DateOfComment.Date) { await Application.Current.MainPage.DisplayAlert("Message", "Comment for this reservation already exist! You can add just 1 comment for reservation", "Try again"); return; } } request.DateOfComment = DateTime.Now.Date; await _serviceComment.Insert <Data.Model.Comment>(request); await Application.Current.MainPage.DisplayAlert("Message", "Successfully! You added your comment for rented car!", "OK"); var listBooking = await _serviceBooking.Get <List <Data.Model.Booking> >(new BookingSearchRequest { CustomerID = customer.CustomerId }); foreach (var item in listBooking) { if (item.VehicleId == vehicle.VehicleId && item.CustomerId == customer.CustomerId) { if (item.CommentStatus == false) { var req = new BookingUpsert { CustomerId = item.CustomerId, VehicleId = item.VehicleId, StartDate = item.StartDate, EndDate = item.EndDate, RatingStatus = item.RatingStatus, CommentStatus = true }; await _serviceBooking.Update <Data.Model.Booking>(item.BookingId, req); return; } } } } } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", "Somethning went wrong", "Try again"); } }