Ejemplo n.º 1
0
        public void Setup()
        {
            var provider      = Substitute.For <IUserNameProvider>();
            var optionBuilder = new DbContextOptionsBuilder <AppDbContext>();

            optionBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            _context = new AppDbContext(optionBuilder.Options, provider);
            _context.Database.EnsureDeleted();
            _context.Database.EnsureCreated();

            using (var context = new AppDbContext(optionBuilder.Options, provider))
            {
                var date1 = new Availability
                {
                    Id     = Id,
                    Active = true,
                    PricePerNightForAdult = 0,
                    PricePerNightForChild = 0,
                    PricePerPerson        = false,
                    RoomsAvailable        = 1,
                    RoomId = roomId,
                    From   = DateTime.Now,
                    To     = DateTime.Now.AddDays(5)
                };
                var date2 = new Availability
                {
                    Active = true,
                    PricePerNightForAdult = 0,
                    PricePerNightForChild = 0,
                    RoomId         = roomId,
                    PricePerPerson = false,
                    RoomsAvailable = 1,
                    From           = DateTime.Now.AddDays(4),
                    To             = DateTime.Now.AddDays(15)
                };
                context.Availabilities.AddRange(new List <Availability>()
                {
                    date1, date2
                });
                context.SaveChanges();

                var room = new Domain.Room
                {
                    Id         = roomId,
                    PropertyId = propertyId
                };
                context.Rooms.Add(room);
                context.SaveChanges();
            };

            uow      = Substitute.For <AppUnitOfWork>(_context);
            _service = new AvailabilityService(uow);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the features to room.
        /// </summary>
        /// <param name="room">The room.</param>
        private void AddFeaturesToRoom(Room room)
        {
            foreach (DataGridViewRow row in this.Form.FeaturesDataGridView.Rows)
            {
                var cell = row.Cells[IsAddedColumnName] as DataGridViewCheckBoxCell;
                var featureId = (int)row.Cells[IdColumnName].Value;
                Feature feature = DataAccess.Instance.Features.Single(f => f.Id == featureId);

                if (Convert.ToBoolean(cell.Value) == true)
                {
                    room.Features.Add(feature);
                }
                else
                {
                    room.Features.Remove(feature);
                }
            }
        }
Ejemplo n.º 3
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                Domain.Room newRoom = new Domain.Room
                {
                    Title     = request.Title,
                    Id        = request.Id,
                    CreatedAt = DateTime.Now,
                    About     = request.About,
                    Username  = request.Username
                };

                _context.Rooms.Add(newRoom);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem saving room");
            }
Ejemplo n.º 4
0
 /// <summary>
 ///  Insert Room to the database
 /// </summary>
 /// <param name="room">The Room to be inserted</param>
 public void insertRoom(Room room)
 {
     string sql;
     sql = "INSERT INTO Room (Number, Capacity, RoomType, SlotsOff, Deleted) VALUES(";
     sql += "'"+room.roomNumber+"', ";
     sql += room.capacity + ", ";
     sql += "'" + room.roomType + "', ";
     sql += "'" + room.slotsOff + "', false ";
     excuteNonQuery(sql);
 }
Ejemplo n.º 5
0
 /// <summary>
 ///     Update a Room in the database
 /// </summary>
 /// <param name="room">The updated Room</param>
 public void updateRoom(Room room)
 {
     string sql;
     sql = "UPDATE Room";
     sql += "Number='" + room.roomNumber + "', ";
     sql += "BuildingID='" + room.buildingId + "', ";
     sql += "Capacity=" + room.capacity + ", ";
     sql += "RoomType='" + room.roomType + "', ";
     sql += "SlotsOff='" + room.slotsOff + "', ";
     sql += "WHERE ID LIKE " + room.ID;
     excuteNonQuery(sql);
 }
 public void addRoom(Room theRoom)
 {
     dataBaseHelper.insertRoom(theRoom);
     dataBaseHelper.update();
 }
 /// <summary>
 ///     Update a Room in the database
 /// </summary>
 /// <param name="room">The updated Room</param>
 private void updateRoom(Room room)
 {
     string sql;
     sql = "UPDATE Room";
     sql += "Number='" + room.getRoomNumber() + "', ";
     sql += "Capacity=" + room.getCapacity() + ", ";
     sql += "RoomType='" + room.getRoomType() + "', ";
     sql += "SlotsOff='" + room.getSlotsOff() + "', ";
     sql += "WHERE ID LIKE " + room.getID();
     excuteNonQuery(sql);
 }
 /// <summary>
 ///  Insert Room to the database
 /// </summary>
 /// <param name="room">The Room to be inserted</param>
 private void insertRoom(Room room)
 {
     string sql;
     sql = "INSERT INTO Room (Number, Capacity, RoomType, SlotsOff, Deleted) VALUES(";
     sql += "'"+room.getRoomNumber()+"', ";
     sql += room.getCapacity() + ", ";
     sql += "'" + room.getRoomType() + "', ";
     sql += "'" + room.getSlotsOff() + "', false ";
     excuteNonQuery(sql);
 }
Ejemplo n.º 9
0
 /// <summary>
 ///     The constructor of Lesson object with a set of properties.
 /// </summary>
 /// <param name="lecturer">The name of the Lecturer</param>
 /// <param name="module">The name of the Module</param>
 /// <param name="room">The name/number of the Room</param>
 public Lesson(Lecturer lecturer, Module module, Room room)
 {
     setLecturer(lecturer);
     setModule(module);
     setRoom(room);
 }
Ejemplo n.º 10
0
 /// <summary>
 ///     Check is a room part on the roomList for this Building
 /// </summary>
 /// <param name="room">Room object to search for in the list</param>
 /// <returns>Wether or not the room is on the lisr</returns>
 public bool isPartOf(Room room)
 {
     return roomList.searchList(room);
 }
Ejemplo n.º 11
0
 /// <summary>
 ///     The constructor of Lesson object with a set of properties.
 /// </summary>
 /// <param name="lecturer">The name of the Lecturer</param>
 /// <param name="module">The name of the Module</param>
 /// <param name="room">The name/number of the Room</param>
 public Lesson(Lecturer lecturer, Module module, Room room)
 {
     this.lecturer = lecturer;
     this.module = module;
     this.room = room;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Rooms EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRooms(Room room)
 {
     base.AddObject("Rooms", room);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Create a new Room object.
 /// </summary>
 /// <param name="number">Initial value of the Number property.</param>
 /// <param name="typeId">Initial value of the TypeId property.</param>
 /// <param name="capacity">Initial value of the Capacity property.</param>
 /// <param name="floor">Initial value of the Floor property.</param>
 /// <param name="vacancy">Initial value of the Vacancy property.</param>
 public static Room CreateRoom(global::System.Int32 number, global::System.Int32 typeId, global::System.Int32 capacity, global::System.Int32 floor, global::System.Boolean vacancy)
 {
     Room room = new Room();
     room.Number = number;
     room.TypeId = typeId;
     room.Capacity = capacity;
     room.Floor = floor;
     room.Vacancy = vacancy;
     return room;
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Handles the Click event of the OkButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void OkButton_Click(object sender, EventArgs e)
        {
            int roomNumber = 0;
            int roomFloor = 0;
            int roomCapacity = 0;
            int roomType = 0;

            int.TryParse(this.Form.NumberTextBox.Text, out roomNumber);
            int.TryParse(this.Form.FloorTextBox.Text, out roomFloor);
            int.TryParse(this.Form.CapacityTextBox.Text, out roomCapacity);
            int.TryParse(this.Form.TypeComboBox.SelectedValue.ToString(), out roomType);

            if (roomNumber <= 0 || roomFloor < 0 || roomCapacity <= 0 || roomType <= 0)
            {
                MessageBox.Show(
                    "Podane wartości nie są prawidłowe lub pozostawiono niewypełnione pola.",
                    "Błąd",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation,
                    MessageBoxDefaultButton.Button1);

                return;
            }

            Room room = null;
            if (this.IsEditForm)
            {
                room = DataAccess.Instance.Rooms.Single(r => r.Number == this.ItemToEditID);
                room.Number = roomNumber;
                room.Capacity = roomCapacity;
                room.Floor = roomFloor;
                room.TypeId = roomType;

                this.AddFeaturesToRoom(room);
            }
            else
            {
                room = new Room
                {
                    Number = roomNumber,
                    Capacity = roomCapacity,
                    Floor = roomFloor,
                    TypeId = roomType
                };

                DataAccess.Instance.Rooms.Add(room);
                this.AddFeaturesToRoom(room);
            }

            try
            {
                DataAccess.Instance.UnitOfWork.Commit();
            }
            catch (Exception)
            {
                MessageBox.Show("Pokój o danym numerze już istnieje!");
                DataAccess.Instance.UnitOfWork.Refresh(room);
            }

            this.Form.Dispose();
        }
Ejemplo n.º 15
0
 /// <summary>
 /// load room list from the database
 /// </summary>
 private void loadRoomList()
 {
     Room tempRoom;
     string sqlStatment = "SELECT * FROM Room ";
     try
     {
         OpenConection();
         cmd = new OleDbCommand(sqlStatment, conn);
         reader = cmd.ExecuteReader();
         while (reader.Read())
         {
             if (reader["Deleted"].ToString().Equals("False"))
             {
                 tempRoom = new Room(
                 reader["Id"].ToString(),
                 reader["Number"].ToString(),
                 Convert.ToInt32(reader["Capacity"]),
                 reader["RoomType"].ToString(),
                 reader["SlotsOff"].ToString(),
                 reader["BuildingID"].ToString());
                 roomList.addAtTail(tempRoom);
             }
         }
         CloseConnection();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
     }
  }
Ejemplo n.º 16
0
        public void insertLessons(Lesson[][] thelessons, Room[] roomList)
=======
Ejemplo n.º 17
0
 /// <summary>
 ///     Adds a room to the roomList
 /// </summary>
 /// <param name="room">Room object to be added to the list</param>
 public void addRoom(Room room)
 {
     roomList.addAtTail(room);
 }
Ejemplo n.º 18
0
 /// <summary>
 ///     Load the LinkedList of Room for a Building
 /// </summary>
 /// <param name="building">The Building the Rooms are in</param>
 /// <returns>Linked List of rooms</returns>
 public LinkedList loadRoomList(Building building)
 {
     LinkedList roomList = new LinkedList();
     Room tempRoom;
     string sqlStatment = "SELECT * FROM Room WHERE BuildingID LIKE  " + building.getID();
     try
     {
         OpenConection();
         cmd = new OleDbCommand(sqlStatment, conn);
         reader = cmd.ExecuteReader();
         while (reader.Read())
         {
             if (reader["Deleted"].ToString().Equals("False"))
             {
                 tempRoom = new Room();
                 tempRoom.setID(reader["ID"].ToString());
                 tempRoom.setRoomNumber(reader["Number"].ToString());
                 tempRoom.setCapacity(Convert.ToInt32(reader["Capacity"]));
                 tempRoom.setRoomType(reader["RoomType"].ToString());
                 tempRoom.setSlotsOff(reader["SlotsOff"].ToString());
                 roomList.addAtTail(tempRoom);
             }
         }
         CloseConnection();
     }
     catch
     {
         // MessageBox.Show("Failed to get data from source");
     }
     return roomList;
 }
Ejemplo n.º 19
0
 /// <summary>
 ///     The parameter received will used for setting the room for the Lesson.
 /// </summary>
 /// <param name="room">Room details</param>
 public void setRoom(Room room)
 {
     this.room = room;
 }