public Types.booking_description_response GetBooking(int bookingId) { Models.apartma2Entities entities = new Models.apartma2Entities(); try { Models.booking bookingModel = entities.bookings.FirstOrDefault(el => el.id.Equals(bookingId)); if (bookingModel != null) { return(PublicTypeConverter.BookingModelToBookingDescriptionResponse(bookingModel)); } else { return(null); } } catch (Exception ex) { return(null); } }
public int AddBooking(int user_trr, int apartmentId, int dateFrom, int dateTo, int packagArrangementId, string discountCode) { Models.apartma2Entities entities = new Models.apartma2Entities(); try { Models.discount discountModel = entities.discounts.FirstOrDefault(el => el.code.Equals(discountCode)); Models.booking bookingModel = new Models.booking { date_from = dateFrom, date_to = dateTo, arrangement_package_id = packagArrangementId, discounts_id = discountModel != null ? discountModel.id : -1 }; return(bookingModel.id); } catch (Exception ex) { return(-1); } }
public bool AddBooking(int userId, int apartmentId, int dateFrom, int dateTo, int packagArrangementId, string discountCode) { Models.ApartmentEntities entities = new Models.ApartmentEntities(); try { Models.discount discountModel = entities.discounts.FirstOrDefault(el => el.code.Equals(discountCode)); Models.booking bookingModel = new Models.booking { customer_idcustomer = userId, date_from = dateFrom, date_to = dateTo, arrangement_package_id = packagArrangementId, discounts_id = discountModel != null ? discountModel.id : -1 }; return(true); } catch (Exception ex) { return(false); } }
public bool CancleBooking(int bookingId) { Models.apartma2Entities entities = new Models.apartma2Entities(); try { Models.booking booking = entities.bookings.FirstOrDefault(el => el.id.Equals(bookingId)); if (booking != null) { booking.status = "cancelled"; entities.Entry(booking).State = System.Data.Entity.EntityState.Modified; entities.SaveChanges(); return(true); } else { return(false); } } catch (Exception ex) { return(false); } }
public List <Types.apartment> AdvancedSearch(int dateFrom, int dateTo, int numOfKingBeds, int numOfSingleBeds, int numOfExtraBeds, bool petFriendly, bool internet, bool airContitioning, bool tv, bool kitchen, int stars, bool balcony, bool accessable) { Models.apartma2Entities entities = new Models.apartma2Entities(); try { List <Models.apartment> result = entities.apartments.ToList(); // filter by avilability if (dateFrom != -1 && dateTo != -1) { List <Models.apartment> tmp = entities.apartments.ToList(); foreach (Models.apartment ap in result) { if (ap.bookings.Count > 0) { Models.booking b = ap.bookings.FirstOrDefault(el => el.date_from >= dateFrom || el.date_to <= dateTo); if (b == null) { tmp.Add(ap); } } else { tmp.Add(ap); } } result = tmp; } if (numOfKingBeds != -1) { result = result.Where(ap => ap.no_king_beds >= numOfKingBeds).ToList(); } if (numOfSingleBeds != -1) { result = result.Where(ap => ap.no_single_beds >= numOfSingleBeds).ToList(); } if (numOfExtraBeds != -1) { result = result.Where(ap => ap.no_extra_beds >= numOfExtraBeds).ToList(); } if (petFriendly) { result = result.Where(ap => ap.pet_friendly == true).ToList(); } if (petFriendly) { result = result.Where(ap => ap.pet_friendly == true).ToList(); } if (internet) { result = result.Where(ap => ap.internet == true).ToList(); } if (airContitioning) { result = result.Where(ap => ap.air_conditioning == true).ToList(); } if (tv) { result = result.Where(ap => ap.tv == true).ToList(); } if (kitchen) { result = result.Where(ap => ap.kitchen == true).ToList(); } if (stars != -1) { result = result.Where(ap => ap.class_stars >= stars).ToList(); } if (balcony) { result = result.Where(ap => ap.balcony == true).ToList(); } if (accessable) { result = result.Where(ap => ap.accessible == true).ToList(); } return(result.Select(el => ApartmentTypeConverter.ApartmentModelToObj(el)).ToList()); } catch (Exception ex) { return(new List <Types.apartment>()); } }
public static Types.booking_description_response BookingModelToBookingDescriptionResponse(Models.booking model) { Types.booking_description_response responseObj = new Types.booking_description_response(); responseObj.apartment_id = model.apartment.id; responseObj.apartment_number = model.apartment.id.ToString(); responseObj.apartment_title = model.apartment.title; responseObj.date_from = model.date_from; responseObj.date_to = model.date_to; responseObj.status = StringToBookingStatusEnum(model.status); return(responseObj); }