예제 #1
0
        /// <summary>
        /// Returns all types from the database
        /// </summary>
        /// <returns></returns>
        public static List<Type> GetAll()
        {
            DataClassesDataContext dbo = new DataClassesDataContext();

            return dbo.Types.ToList();
        }
예제 #2
0
        /// <summary>
        /// returns all regions, ordered by name
        /// </summary>
        /// <returns></returns>
        public static List<GentRegion> GetAll()
        {
            DataClassesDataContext dbo = new DataClassesDataContext();

            return dbo.GentRegions.OrderBy(r => r.Name).ToList();
        }
예제 #3
0
        /// <summary>
        /// Gets a certain room by its id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Room GetById(int id)
        {
            DataClassesDataContext dbo = new DataClassesDataContext();

            return dbo.Rooms.SingleOrDefault(r => r.ID == id);
        }
예제 #4
0
        /// <summary>
        /// Gets all rooms according to a filter
        /// </summary>
        /// <param name="filter">filter object used to filter the rooms</param>
        /// <returns></returns>
        public static List<Room> GetFiltered(FilterObject filter)
        {
            DataClassesDataContext dbo = new DataClassesDataContext();

            var rooms = dbo.Rooms.Where(r => r.ID > -1);

            if (filter.Type.HasValue && filter.Type.Value != -1) rooms = rooms.Where(r => r.TypeId == filter.Type.Value);

            if (filter.MinPrice.HasValue) rooms = rooms.Where(r => r.Price >= filter.MinPrice.Value);
            if (filter.MaxPrice.HasValue) rooms = rooms.Where(r => r.Price <= filter.MaxPrice.Value);

            if (filter.Included) rooms = rooms.Where(r => r.Included == filter.Included);

            if (filter.MinSize.HasValue) rooms = rooms.Where(r => r.Size >= filter.MinSize.Value);
            if (filter.MaxSize.HasValue) rooms = rooms.Where(r => r.Size <= filter.MaxSize.Value);

            if (filter.Attributes != null && filter.Attributes.Length > 0) {
                rooms = rooms.Where(r => dbo.RoomHasAttributes.Where(a => filter.Attributes.Contains(a.AttributeId)).Select(a => a.RoomID).Contains(r.ID));
            }

            if (filter.Region.HasValue) rooms = rooms.Where(r => r.RegionId == filter.Region.Value);

            if (filter.Query != null && filter.Query != "") {
                foreach (string q in filter.Query.Split(' ')) {
                    rooms = rooms.Where(r =>
                     SqlMethods.Like(r.KotUser.Username, "%" + q + "%") ||
                     SqlMethods.Like(r.Location, "%" + q + "%") ||
                     SqlMethods.Like(r.Decsription, "%" + q + "%") ||
                     SqlMethods.Like(r.Address, "%" + q + "%"));
                }
            }

            if (filter.Sort.HasValue) {
                switch (filter.Sort.Value) {

                    case RoomSorts.Toegevoegd:
                        if (!filter.Reversed) rooms = rooms.OrderByDescending(r => r.Added);
                        else rooms = rooms.OrderBy(r => r.Added);
                        break;

                    case RoomSorts.Prijs:
                        if (!filter.Reversed) rooms = rooms.OrderBy(r => r.Price).ThenBy(r => r.Added);
                        else rooms = rooms.OrderByDescending(r => r.Price).ThenBy(r => r.Added);
                        break;

                    case RoomSorts.Regio:
                        if (!filter.Reversed) rooms = rooms.OrderBy(r => r.GentRegion.Name).ThenBy(r => r.Address);
                        else rooms = rooms.OrderByDescending(r => r.GentRegion.Name).ThenByDescending(r => r.Address);
                        break;

                    case RoomSorts.Grootte:
                        if (!filter.Reversed) rooms = rooms.OrderBy(r => r.Size).ThenBy(r => r.Added);
                        else rooms = rooms.OrderByDescending(r => r.Size).ThenBy(r => r.Added);
                        break;

                    case RoomSorts.Type:
                        if (!filter.Reversed) rooms = rooms.OrderBy(r => r.Type.Name).ThenBy(r => r.Added);
                        else rooms = rooms.OrderByDescending(r => r.Type.Name).ThenBy(r => r.Added);
                        break;
                }
            }

            return rooms.ToList();
        }
예제 #5
0
        /// <summary>
        /// Checks wether or not this room is reserved
        /// </summary>
        /// <returns></returns>
        public bool IsReserved()
        {
            DataClassesDataContext dbo = new DataClassesDataContext();

            return dbo.UserSavesRooms.SingleOrDefault(s => s.RoomId == this.ID && s.DateSaved > DateTime.Now.AddHours(-24)) != null;
        }
예제 #6
0
        /// <summary>
        /// gets the save objects for this room
        /// </summary>
        /// <returns></returns>
        private List<UserSavesRoom> GetSaves()
        {
            DataClassesDataContext dbo = new DataClassesDataContext();

            return dbo.UserSavesRooms.Where(s => s.RoomId == this.ID).ToList();
        }
예제 #7
0
        /// <summary>
        /// Gets all rooms in the same region, sorted by the price difference
        /// </summary>
        /// <returns></returns>
        public List<Room> GetRelated()
        {
            DataClassesDataContext dbo = new DataClassesDataContext();

            return dbo.Rooms.Where(r => r.RegionId == this.RegionId && r.ID != this.ID).OrderBy(r => Math.Abs(r.Price - this.Price)).ToList();
        }
예제 #8
0
        /// <summary>
        /// Gets all attributes this room has
        /// </summary>
        /// <returns></returns>
        public List<RoomHasAttribute> GetAttributes()
        {
            DataClassesDataContext dbo = new DataClassesDataContext();

            return dbo.RoomHasAttributes.Where(l => l.RoomID == this.ID).ToList();
        }
예제 #9
0
        /// <summary>
        /// gets an array with the names of this room's attributes
        /// </summary>
        /// <returns></returns>
        public string[] GetAttributeNames()
        {
            DataClassesDataContext dbo = new DataClassesDataContext();

            return dbo.RoomHasAttributes.Where(l => l.RoomID == this.ID).Select(a => dbo.Attributes.Single(t => t.ID == a.AttributeId).Name).ToArray();
        }
예제 #10
0
        /// <summary>
        /// Gets all rooms ordered by their distance from a point
        /// </summary>
        /// <param name="lat">lat of the point</param>
        /// <param name="lng">long of the point</param>
        /// <returns></returns>
        public static List<Room> GetNear(double lat, double lng)
        {
            DataClassesDataContext dbo = new DataClassesDataContext();

            return dbo.Rooms.OrderBy(r => Math.Sqrt(Math.Pow(r.Lat - lat, 2) + Math.Pow(r.Long - lng, 2))).ToList();
        }
예제 #11
0
        /// <summary>
        /// Gets the name of an attribute
        /// </summary>
        /// <returns></returns>
        public string GetAttributeName()
        {
            DataClassesDataContext dbo = new DataClassesDataContext();

            return dbo.Attributes.Single(a => a.ID == this.AttributeId).Name;
        }