public void CreateDestination(DestinationDTO destinationDto) { Destination destination = new Destination { Destination_ID = destinationDto.Destination_ID, Is_Abroad = destinationDto.Is_Abroad, Country = destinationDto.Country, City = destinationDto.City, }; this.Database.Destinations.Create(destination); this.Database.Save(); }
public TripViewModel(TripDTO trip, DestinationDTO destination, DatesRangeDTO datesRange) { this.Trip_ID = trip.Trip_ID; this.Trip_Title = trip.Trip_Title; this.Description = trip.Description; this.Price = trip.Price; this.Date_ID = trip.Date_ID; this.Number_Of_People = trip.Number_Of_People; this.Creator_ID = trip.Creator_ID; this.Start_date = datesRange.Start_date; this.End_date = datesRange.End_date; this.Destination_ID = trip.Destination_ID; this.Is_Abroad = destination.Is_Abroad; this.Country = destination.Country; this.City = destination.City; }
public void CreateTrip(TripDTO tripDto, DestinationDTO destinationDTO, DatesRangeDTO datesRangeDTO) { Trip trip = new Trip { Trip_ID = tripDto.Trip_ID, Trip_Title = tripDto.Trip_Title, Description = tripDto.Description, Price = tripDto.Price, Date_ID = tripDto.Date_ID, Number_Of_People = tripDto.Number_Of_People, Destination_ID = tripDto.Destination_ID, Creator_ID = tripDto.Creator_ID, }; Destination destination = new Destination { Destination_ID = destinationDTO.Destination_ID, Is_Abroad = destinationDTO.Is_Abroad, Country = destinationDTO.Country, City = destinationDTO.City, }; Dates_ranges dates_Ranges = new Dates_ranges { Date_ID = datesRangeDTO.Date_ID, Start_date = datesRangeDTO.Start_date, End_date = datesRangeDTO.End_date, }; try { this.Database.Trips.GetAll().Where(e => e.Trip_Title == trip.Trip_Title).First(); throw new ArgumentNullException(); } catch (System.InvalidOperationException) { this.Database.Destinations.Create(destination); this.Database.Dates_ranges.Create(dates_Ranges); this.Database.Trips.Create(trip); this.Database.Save(); } }
public ActionResult Create(TripViewModel tripModel) { try { tripModel.Trip_ID = this.tripService.FindMaxId() + 1; tripModel.Destination_ID = this.tripService.FindMaxIdDestination() + 1; tripModel.Date_ID = this.tripService.FindMaxIdDateRange() + 1; switch (tripModel.Country.ToLower()) { case "ukraine": tripModel.Is_Abroad = false; break; default: tripModel.Is_Abroad = true; break; } var sessionUserId = int.Parse(this.Session["User_ID"].ToString()); tripModel.Creator_ID = sessionUserId; var tripDto = new TripDTO(tripModel.Trip_ID, tripModel.Trip_Title, tripModel.Description, tripModel.Price, tripModel.Date_ID, tripModel.Number_Of_People, tripModel.Destination_ID, tripModel.Creator_ID); var destinationDto = new DestinationDTO(tripModel.Destination_ID, tripModel.Is_Abroad, tripModel.Country, tripModel.City); var dateDto = new DatesRangeDTO(tripModel.Date_ID, tripModel.Start_date, tripModel.End_date); this.tripService.CreateTrip(tripDto, destinationDto, dateDto); return(this.RedirectToAction("TripDetail", "TripDetail", new { id = tripModel.Trip_ID })); } catch (ArgumentNullException) { this.ViewBag.DuplicateMessage = "Подорож з цією назвою вже існує."; return(this.View("Create")); } catch (System.Data.Entity.Validation.DbEntityValidationException) { this.ModelState.Clear(); return(this.View("Create", tripModel)); } }
public async Task <IActionResult> GetCompanyDetails(long id) { CarCompany company = await CarService.GetCompany(id); CarCompanyProfile companyProfile = new CarCompanyProfile(); CarCompanyProfileDTO carCompanyProfileDTO = new CarCompanyProfileDTO(); List <Office> officeList = company.Offices; List <Vehicle> vehicleList = company.Vehicles; List <int> vehicleRating = new List <int>(); foreach (var vehicle in vehicleList) { vehicleRating.Add(await VehicleService.GetVehicleRatingAsInteger(vehicle.VehicleId)); } int carCompanyRatingPicture = 0; if (ModelState.IsValid) { List <OfficeDTO> officeDTOList = new List <OfficeDTO>(); for (int i = 0; i < officeList.Count; i++) { OfficeDTO officeDTO = new OfficeDTO(); DestinationDTO destinationDTO = new DestinationDTO(); destinationDTO.Latitude = officeList[i].Location.Latitude; destinationDTO.Longitude = officeList[i].Location.Longitude; destinationDTO.Name = officeList[i].Location.Name; officeDTO.OfficeId = officeList[i].OfficeId; officeDTO.Location = destinationDTO; officeDTO.Address = officeList[i].Address; officeDTOList.Add(officeDTO); } List <VehicleDTO> vehicleDTOList = new List <VehicleDTO>(); for (int i = 0; i < vehicleList.Count; i++) { VehicleDTO vehicleDTO = new VehicleDTO(); vehicleDTO.Additional = vehicleList[i].Additional; vehicleDTO.Baggage = vehicleList[i].Baggage; vehicleDTO.CarType = vehicleList[i].CarType; vehicleDTO.CostPerDay = vehicleList[i].CostPerDay; vehicleDTO.Doors = vehicleList[i].Doors; vehicleDTO.Fuel = vehicleList[i].Fuel; vehicleDTO.Name = vehicleList[i].Name; vehicleDTO.Passangers = vehicleList[i].Passangers; vehicleDTO.Rating = vehicleRating[i]; vehicleDTO.Transmission = vehicleList[i].Transmission; vehicleDTO.VehicleId = vehicleList[i].VehicleId; vehicleDTO.Additional = vehicleList[i].Additional; vehicleDTOList.Add(vehicleDTO); } string allOfficies = ""; for (int i = 0; i < officeList.Count; i++) { allOfficies += officeList[i].Location.Name + ","; } companyProfile = await CarService.GetCompanyProfile(id); carCompanyRatingPicture = await CarService.GetCompanyRatingAsInteger(id); carCompanyProfileDTO.Id = company.CarCompanyId; carCompanyProfileDTO.Name = companyProfile.Name; carCompanyProfileDTO.RatingPicture = carCompanyRatingPicture; carCompanyProfileDTO.Address = companyProfile.Address; carCompanyProfileDTO.Description = companyProfile.PromoDescription; carCompanyProfileDTO.OfficeList = officeList; carCompanyProfileDTO.VehicleList = vehicleDTOList; carCompanyProfileDTO.Offices = allOfficies; return(Ok(new { carCompanyProfileDTO })); } ModelState.AddModelError("", "Cannot retrieve user data."); return(BadRequest(ModelState)); }
public Destination DestinationDTOToDestination(DestinationDTO destinationDTO) { return(new Destination()); }