public HotelEntity Create(HotelEntity hotel)
        {
            var result = _context.Hotel.Add(hotel).Entity;

            _context.SaveChanges();
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Obtem as informações do Hotel. No caso, as informações dos quartos cadastrados no mesmo.
        /// </summary>
        /// <returns></returns>
        public HotelEntity GetInfoHotel()
        {
            var infoHotel = new HotelEntity
            {
                QuantityRoom      = _roomRepository.GetAll().Count,
                QuantityRoomBlock = _roomRepository.Find(x => x.Status == RoomStatus.Lock).Count,
                QuantityRoomBusy  = _roomRepository.Find(x => x.Status == RoomStatus.Busy).Count
            };

            return(infoHotel);
        }
Beispiel #3
0
 public void Update(HotelEntity hotel)
 {
     try
     {
         _context.Entry(hotel).State = EntityState.Modified;
         _context.SaveChanges();
     }
     catch
     {
         throw new NotImplementedException();
     }
 }
Beispiel #4
0
 public void Add(HotelEntity hotel)
 {
     try
     {
         _context.Hotels.Add(hotel);
         _context.SaveChanges();
     }
     catch
     {
         throw new NotImplementedException();
     }
 }
Beispiel #5
0
 public HotelDto(HotelEntity hotelEnitity)
 {
     if (hotelEnitity != null)
     {
         Id          = hotelEnitity.Id;
         Nome        = hotelEnitity.Nome;
         Descricao   = hotelEnitity.Descricao;
         Avaliacao   = hotelEnitity.Avaliacao;
         Endereco    = hotelEnitity.Endereco;
         Comodidades = hotelEnitity.Comodidades.Select(comodidadeEntity => new ComodidadeDto(comodidadeEntity)).ToList();
     }
 }
Beispiel #6
0
            /// <summary>
            /// 取得住宿資訊
            /// </summary>
            /// <param name="serialNo">The serial no.</param>
            /// <returns></returns>
            public static HotelEntity Get(string serialNo)
            {
                HotelEntity entity = null;

                using (var openData = new Chinese())
                {
                    var table = openData.GetById(serialNo);

                    entity = table.ToList <HotelEntity>().FirstOrDefault();
                }

                return(entity);
            }
        public HotelEntity Update(HotelEntity hotel)
        {
            HotelEntity existing = _context.Hotel.Find(hotel.Id);

            if (existing != null)
            {
                _context.Hotel.Update(hotel);
                _context.SaveChanges();
                return(hotel);
            }
            else
            {
                return(null);
            }
        }
Beispiel #8
0
        public HotelEntity SelectHotel(int id)
        {
            HotelEntity hotel = null;

            try
            {
                using (SqlConnection db = new SqlConnection())
                {
                    string query = $"SELECT * FROM HOTEL WHERE id ={id}";

                    db.ConnectionString = AppConfig.ConnectionStringAdo;

                    SqlCommand cmd = db.CreateCommand();

                    cmd.CommandText = query;

                    db.Open();

                    SqlDataReader read = cmd.ExecuteReader();

                    if (read.Read())
                    {
                        hotel = new HotelEntity(
                            (int)read[0],
                            read[1].ToString(),
                            (int)read[2],
                            read[3].ToString(),
                            (int)read[4],
                            read[5].ToString(),
                            read[6].ToString(),
                            read[7].ToString(),
                            read[8].ToString(),
                            read[9].ToString(),
                            read[10].ToString(),
                            (int)read[11],
                            (bool)read[12],
                            (bool)read[13],
                            (bool)read[14],
                            read[15].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erreur de DAL", ex);
            }
            return(hotel);
        }
Beispiel #9
0
        public void UpdateHotel(HotelEntity hotel, string currentHotelId)
        {
            if (hotel == null)
            {
                throw new ArgumentException("HotelEntity cannot be null.");
            }
            if (string.IsNullOrEmpty(currentHotelId))
            {
                throw new ArgumentException("currentHotelId cannot be Null or empty.");
            }

            //DB

            using (var unitOfWork = _dependencyResolver.Resolve <IUnitOfWork>())
            {
                unitOfWork.HotelRepository.UpdateHotel(hotel);
                unitOfWork.SaveChanges();
            }
        }
        public HotelEntity GetLowestPriceHotel(RequestLowestPriceDto request)
        {
            var         hotels      = _hotelRepository.GetHotels();
            HotelEntity lowestHotel = null;

            if (request == null ||
                !request.IsValide())
            {
                return(null);
            }

            var weekDays    = request.Dates.Where(x => !IsWeekEnd(x)).Count();
            var weekendDays = request.Dates.Where(x => IsWeekEnd(x)).Count();

            foreach (var hotel in hotels)
            {
                if (lowestHotel == null)
                {
                    lowestHotel = hotel;
                    continue;
                }

                var actualHotelDaily = hotel.DailyValue(weekDays, weekendDays, request.ClientType);
                var lowestHotelDaily = lowestHotel.DailyValue(weekDays, weekendDays, request.ClientType);

                if (actualHotelDaily == lowestHotelDaily)
                {
                    lowestHotel = lowestHotel.Rating > hotel.Rating ? lowestHotel : hotel;
                }

                if (actualHotelDaily < lowestHotelDaily)
                {
                    lowestHotel = hotel;
                }
            }

            return(lowestHotel);
        }
Beispiel #11
0
 internal Hotel(HotelEntity entity)
 {
     _backingField = entity;
 }