public bool UpdateBooking(booking bookingObj)
        {
            Models.apartma2Entities entities = new Models.apartma2Entities();
            try
            {
                Models.booking bookingModel = entities.bookings.FirstOrDefault(el => el.id.Equals(bookingObj.id));
                if (bookingModel != null)
                {
                    bookingModel.id        = bookingObj.id;
                    bookingModel.date_from = bookingObj.date_from;
                    bookingModel.date_to   = bookingObj.date_to;
                    bookingModel.status    = bookingObj.status.ToString();
                    bookingModel.apartment = ApartmentTypeConverter.ApartmentObjToModel(bookingObj.apartment);
                    //bookingModel.customer = ApartmentTypeConverter.CustomerObjToModel(bookingObj.customer);
                    bookingModel.payment_method = ApartmentTypeConverter.PaymentObjToModel(bookingObj.payment);
                    bookingModel.discount       = ApartmentTypeConverter.DiscountObjToModel(bookingObj.discount);

                    entities.Entry(bookingModel).State = System.Data.Entity.EntityState.Modified;
                    entities.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
 public booking GetBooking(int id, int userId, int apartmentId, int dateFrom, int dateTo)
 {
     Models.apartma2Entities entities = new Models.apartma2Entities();
     try
     {
         Models.booking bookingModel = entities.bookings.FirstOrDefault(el => el.id.Equals(id) || el.customer_trr.Equals(userId) || el.apartment.id.Equals(apartmentId) ||
                                                                        (el.date_from >= dateFrom && el.date_to <= dateTo));
         if (bookingModel != null)
         {
             booking bookingObj = new booking
             {
                 id        = bookingModel.id,
                 date_from = bookingModel.date_from,
                 date_to   = bookingModel.date_to,
                 //customer = ApartmentTypeConverter.CustomerModelToObj(bookingModel.customer),
                 apartment = ApartmentTypeConverter.ApartmentModelToObj(bookingModel.apartment),
                 status    = ApartmentTypeConverter.BookingStatusStringToEnum(bookingModel.status),
                 discount  = ApartmentTypeConverter.DiscountModelToObj(bookingModel.discount),
                 payment   = ApartmentTypeConverter.PaymentModelToObj(bookingModel.payment_method)
             };
             return(bookingObj);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
        public apartment[] FindApartment(int id, int num_of_beds)
        {
            Models.apartma2Entities entities = new Models.apartma2Entities();
            try
            {
                List <Models.apartment> apartmentModels = new List <Models.apartment>();

                if (id == 0 && num_of_beds == 0)
                {
                    apartmentModels = entities.apartments.ToList();
                }
                else if (id > 0)
                {
                    apartmentModels = entities.apartments.Where(el => el.id.Equals(id)).ToList();
                }
                else
                {
                    apartmentModels = entities.apartments.Where(el => el.no_extra_beds + el.no_king_beds * 2 + el.no_single_beds >= num_of_beds).ToList();
                }

                if (apartmentModels != null)
                {
                    return(apartmentModels.Select(el => Models.Utils.ApartmentTypeConverter.ApartmentModelToObj(el)).ToArray());
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public int AddApartment(apartment apartmentObj)
        {
            try
            {
                Models.apartma2Entities entities = new Models.apartma2Entities();

                Models.apartment apartmentModel = new Models.apartment
                {
                    accessible       = apartmentObj.accessible,
                    air_conditioning = apartmentObj.air_conditioning,
                    class_stars      = apartmentObj.class_stars,
                    description      = apartmentObj.description,
                    latitude         = (float?)apartmentObj.latitude,
                    longitude        = (float?)apartmentObj.longitude,
                    no_extra_beds    = apartmentObj.no_extra_beds,
                    no_single_beds   = apartmentObj.no_single_beds,
                    no_king_beds     = apartmentObj.no_king_beds,
                    tv           = apartmentObj.tv,
                    title        = apartmentObj.title,
                    pet_friendly = apartmentObj.pet_friendly,
                    internet     = apartmentObj.internet,
                    kitchen      = apartmentObj.kitchen
                };


                entities.apartments.Add(apartmentModel);
                entities.SaveChanges();

                return(apartmentModel.id);
            }
            catch (Exception ex)
            {
                return(-1);
            }
        }
        public bool UpdateDiscoint(discount discountObj)
        {
            Models.apartma2Entities entities = new Models.apartma2Entities();
            try
            {
                Models.discount discountModel = entities.discounts.FirstOrDefault(el => el.id.Equals(discountObj.id));
                if (discountModel != null)
                {
                    discountModel.id                  = discountObj.id;
                    discountModel.code                = discountObj.code;
                    discountModel.title               = discountObj.title;
                    discountModel.valid_to            = discountObj.valid_to;
                    discountModel.valid_from          = discountObj.valid_from;
                    discountModel.discount_percentage = (float)discountObj.discount_percentage;

                    entities.Entry(discountModel).State = System.Data.Entity.EntityState.Modified;
                    entities.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public bool UpdatePackageArrangements(arrangement_package arrangementObj)
        {
            Models.apartma2Entities entities = new Models.apartma2Entities();
            try
            {
                Models.arrangement_package arrangementModel = entities.arrangement_package.FirstOrDefault(el => el.id.Equals(arrangementObj.id));
                if (arrangementModel != null)
                {
                    arrangementModel.id              = arrangementObj.id;
                    arrangementModel.title           = arrangementObj.title;
                    arrangementModel.description     = arrangementObj.description;
                    arrangementModel.max_resevations = arrangementObj.max_reservations.ToString();
                    arrangementModel.valid_to        = arrangementObj.valid_to;
                    arrangementModel.valid_from      = arrangementObj.valid_from;
                    arrangementModel.price           = (float)arrangementObj.price;

                    entities.Entry(arrangementModel).State = System.Data.Entity.EntityState.Modified;
                    entities.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public int MakeBooking(string user_trr, int apartmentId, int dateFrom, int dateTo, int package_arrangment_id, string discountCode, bool bank_payment)
        {
            Models.apartma2Entities entities = new Models.apartma2Entities();
            try
            {
                Models.apartment apartmentModel = entities.apartments.FirstOrDefault(el => el.id.Equals(apartmentId));

                if (apartmentModel != null)
                {
                    Models.payment_method method = new Models.payment_method();
                    method.bank_payment = bank_payment;                     // true -> e-bull; false -> card
                    method.card_number  = user_trr.ToString();

                    Models.booking newBooking = new Models.booking();
                    newBooking.customer_trr          = user_trr;
                    newBooking.apartment_idapartment = apartmentId;
                    newBooking.date_from             = dateFrom;
                    newBooking.date_to        = dateTo;
                    newBooking.payment_method = method;

                    if (bank_payment)
                    {
                        newBooking.status = "pending";
                    }
                    else
                    {
                        newBooking.status = "paid";
                    }

                    Models.arrangement_package arrangementModel = entities.arrangement_package.FirstOrDefault(el => el.id.Equals(package_arrangment_id));
                    Models.discount            discountModel    = entities.discounts.FirstOrDefault(el => el.code.Equals(discountCode));

                    if (arrangementModel != null)
                    {
                        newBooking.arrangement_package_id = arrangementModel.id;
                    }


                    if (discountModel != null)
                    {
                        newBooking.discounts_id = discountModel.id;
                    }

                    entities.bookings.Add(newBooking);
                    entities.SaveChanges();
                    return(newBooking.id);
                }
                else
                {
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                return(-1);
            }
        }
 public int AddDiscount(discount discountObj)
 {
     Models.apartma2Entities entities = new Models.apartma2Entities();
     try
     {
         Models.discount discountModel = ApartmentTypeConverter.DiscountObjToModel(discountObj);
         entities.discounts.Add(discountModel);
         entities.SaveChanges();
         return(discountModel.id);
     }
     catch (Exception ex)
     {
         return(-1);
     }
 }
 public int AddPackageArrangments(arrangement_package arrangmentObj)
 {
     Models.apartma2Entities entities = new Models.apartma2Entities();
     try
     {
         Models.arrangement_package arrangmentModel = ApartmentTypeConverter.ArrangmentObjToModel(arrangmentObj);
         entities.arrangement_package.Add(arrangmentModel);
         entities.SaveChanges();
         return(arrangmentModel.id);
     }
     catch (Exception ex)
     {
         return(-1);
     }
 }
Example #10
0
        public List <Types.apartment> Search(int dateFrom, int dateTo, int numOfBeds)
        {
            Models.apartma2Entities entities = new Models.apartma2Entities();
            try
            {
                List <Models.apartment> result = entities.apartments.ToList();

                if (numOfBeds != -1)
                {
                    result = entities.apartments.Where(ap => ap.no_single_beds + ap.no_king_beds * 2 + ap.no_extra_beds >= numOfBeds).ToList();
                }

                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;
                }

                return(result.Select(el => ApartmentTypeConverter.ApartmentModelToObj(el)).ToList());
            }
            catch (Exception ex)
            {
                return(new List <Types.apartment>());
            }
        }
Example #11
0
 public Types.arrangement_package[] GetPackagesArrangements(int dateFrom, int dateTo)
 {
     Models.apartma2Entities entities = new Models.apartma2Entities();
     try
     {
         List <Models.arrangement_package> packagesList = entities.arrangement_package.Where(el => el.valid_from >= dateFrom && el.valid_to <= dateTo).ToList();
         if (packagesList != null)
         {
             return(packagesList.Select(el => Models.Utils.ApartmentTypeConverter.ArrangmentModelToObj(el)).ToArray());
         }
         else
         {
             return(new Types.arrangement_package[] { });
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Example #12
0
 public Types.discount[] GetDiscounts(int dateFrom, int dateTo)
 {
     Models.apartma2Entities entities = new Models.apartma2Entities();
     try
     {
         List <Models.discount> discountsList = entities.discounts.Where(el => el.valid_from >= dateFrom && el.valid_to <= dateTo).ToList();
         if (discountsList != null)
         {
             return(discountsList.Select(el => Models.Utils.ApartmentTypeConverter.DiscountModelToObj(el)).ToArray());
         }
         else
         {
             return(new Types.discount[] { });
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Example #13
0
 public Types.booking_description_response[] GetBookingsForApppartment(int apartmentId)
 {
     Models.apartma2Entities entities = new Models.apartma2Entities();
     try
     {
         List <Models.booking> bookingModelList = entities.bookings.Where(el => el.apartment.id.Equals(apartmentId)).ToList();
         if (bookingModelList != null)
         {
             return(bookingModelList.Select(el => PublicTypeConverter.BookingModelToBookingDescriptionResponse(el)).ToArray());
         }
         else
         {
             return(new Types.booking_description_response[] {});
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Example #14
0
 public Types.booking_description_response[] GetBookingsForUser(string userTrr)
 {
     Models.apartma2Entities entities = new Models.apartma2Entities();
     try
     {
         List <Models.booking> bookingModelList = entities.bookings.Where(el => el.customer_trr.Equals(userTrr)).ToList();
         if (bookingModelList != null)
         {
             return(bookingModelList.Select(el => PublicTypeConverter.BookingModelToBookingDescriptionResponse(el)).ToArray());
         }
         else
         {
             return(new Types.booking_description_response[] { });
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Example #15
0
 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 DeletePackageArrangments(int arrangementId)
 {
     Models.apartma2Entities entities = new Models.apartma2Entities();
     try
     {
         Models.arrangement_package arrangementModel = entities.arrangement_package.FirstOrDefault(el => el.id.Equals(arrangementId));
         if (arrangementModel != null)
         {
             entities.Entry(arrangementModel).State = System.Data.Entity.EntityState.Deleted;
             entities.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
        public arrangement_package[] GetPackageArrangments(int dateFrom, int dateTo)
        {
            Models.apartma2Entities entities = new Models.apartma2Entities();
            try
            {
                List <Models.arrangement_package> packageModels = new List <Models.arrangement_package>();

                if (dateFrom == 0 && dateTo == 0)
                {
                    packageModels = entities.arrangement_package.ToList();
                }
                else
                {
                    packageModels = entities.arrangement_package.Where(el => el.valid_from >= dateFrom && el.valid_to <= dateTo).ToList();
                }
                return(packageModels.Select(el => ApartmentTypeConverter.ArrangmentModelToObj(el)).ToArray());
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
 public bool DeleteDiscount(int discountId)
 {
     Models.apartma2Entities entities = new Models.apartma2Entities();
     try
     {
         Models.discount discountModel = entities.discounts.FirstOrDefault(el => el.id.Equals(discountId));
         if (discountModel != null)
         {
             entities.Entry(discountModel).State = System.Data.Entity.EntityState.Deleted;
             entities.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
        public bool UpdateApartment(apartment apartmentObj)
        {
            Models.apartma2Entities entities = new Models.apartma2Entities();
            try
            {
                Models.apartment apartmentModel = entities.apartments.FirstOrDefault(el => el.id.Equals(apartmentObj.id));

                if (apartmentModel != null)
                {
                    apartmentModel.accessible       = apartmentObj.accessible;
                    apartmentModel.air_conditioning = apartmentObj.air_conditioning;
                    apartmentModel.class_stars      = apartmentObj.class_stars;
                    apartmentModel.description      = apartmentObj.description;
                    apartmentModel.latitude         = (float?)apartmentObj.latitude;
                    apartmentModel.longitude        = (float?)apartmentObj.longitude;
                    apartmentModel.no_extra_beds    = apartmentObj.no_extra_beds;
                    apartmentModel.no_single_beds   = apartmentObj.no_single_beds;
                    apartmentModel.no_king_beds     = apartmentObj.no_king_beds;
                    apartmentModel.tv           = apartmentObj.tv;
                    apartmentModel.title        = apartmentObj.title;
                    apartmentModel.pet_friendly = apartmentObj.pet_friendly;
                    apartmentModel.internet     = apartmentObj.internet;
                    apartmentModel.kitchen      = apartmentObj.kitchen;

                    entities.Entry(apartmentModel).State = System.Data.Entity.EntityState.Modified;
                    entities.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Example #21
0
 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);
     }
 }
Example #22
0
        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>());
            }
        }