Beispiel #1
0
 /// <summary>
 /// Logic.AmenityRoom => Entity.AmenityRoom
 /// </summary>
 /// <param name="ar"></param>
 /// <returns></returns>
 public Entity.AmenityRoom MapAmenityRoomtoE(Logic.AmenityRoom ar)
 {
     return(new Entity.AmenityRoom
     {
         AmenityRoomId = ar.AmenityRoomId,
         AmenityId = ar.AmenityId,
         RoomId = ar.RoomId
     });
 }
        public async void PostRoomsAsyncTest()
        {
            var amId    = Guid.NewGuid();
            var cId     = Guid.NewGuid();
            var rId     = Guid.NewGuid();
            var amenity = new ApiAmenity
            {
                AmenityId   = amId,
                AmenityType = "Pool",
                Description = "swimmming"
            };
            var amenities = new List <ApiAmenity>
            {
                amenity
            };
            var ar = new Logic.AmenityRoom
            {
                AmenityRoomId = Guid.NewGuid(),
                AmenityId     = amId,
                RoomId        = rId
            };
            var room = new ApiRoom
            {
                RoomId       = rId,
                RoomNumber   = "1234",
                ComplexId    = cId,
                ApiRoomType  = "dorm",
                NumberOfBeds = 3,
                LeaseStart   = Convert.ToDateTime("2010/1/1"),
                LeaseEnd     = Convert.ToDateTime("2020/1/1"),
                Amenities    = amenities
            };
            var rooms = new List <ApiRoom>
            {
                room
            };
            IEnumerable <ApiRoom> apiRooms = rooms;
            var complexRepo = new Mock <IRepository>();
            var logger      = new Mock <ILogger <ComplexController> >();
            var rss         = new Mock <IRoomServiceSender>();
            var ara         = new Mock <IAddressRequest>();
            var rr          = new Mock <IRoomRequest>();
            var res         = true;

            complexRepo.Setup(r => r.CreateAmenityRoomAsync(ar))
            .Returns(Task.FromResult(res));

            //act
            var controller = new ComplexController(complexRepo.Object, logger.Object, rss.Object, ara.Object, rr.Object);
            var model      = Assert.IsAssignableFrom <StatusCodeResult>(await controller.PostRoomsAsync(apiRooms));

            //assert
            Assert.IsAssignableFrom <StatusCodeResult>(model);
        }
Beispiel #3
0
        /// <summary>
        /// Create new single Amenities of Room in database by amenityroom object
        /// </summary>
        /// <param name="ar"></param>
        /// <returns></returns>
        public async Task <bool> CreateAmenityRoomAsync(Logic.AmenityRoom ar)
        {
            var amenityRoom = _map.MapAmenityRoomtoE(ar);

            await _context.AddAsync(amenityRoom);

            await _context.SaveChangesAsync();

            _log.LogInformation("new amenity of room id: {roomId}", ar.RoomId);

            return(true);
        }
        public void AmenityRoomTest()
        {
            var arId = Guid.NewGuid();
            var amId = Guid.NewGuid();
            var rId  = Guid.NewGuid();

            var ar = new Logic.AmenityRoom
            {
                AmenityRoomId = arId,
                AmenityId     = amId,
                RoomId        = rId
            };

            Assert.Equal(arId, ar.AmenityRoomId);
            Assert.Equal(amId, ar.AmenityId);
            Assert.Equal(rId, ar.RoomId);
        }
Beispiel #5
0
        //POST: api/complex/PostRooms
        public async Task <ActionResult> PostRoomsAsync([FromBody] IEnumerable <ApiRoom> apiRooms)
        {
            var apiRoomtoSends = new List <ApiRoomtoSend>();
            var amenityRoom    = new Logic.AmenityRoom();

            try
            {
                foreach (var apiRoom in apiRooms)
                {
                    var arts = new ApiRoomtoSend
                    {
                        RoomId       = Guid.NewGuid(),
                        RoomNumber   = apiRoom.RoomNumber,
                        ComplexId    = apiRoom.ComplexId,
                        NumberOfBeds = apiRoom.NumberOfBeds,
                        RoomType     = apiRoom.ApiRoomType,
                        LeaseStart   = apiRoom.LeaseStart,
                        LeaseEnd     = apiRoom.LeaseEnd,
                        QueOperator  = 0,
                    };

                    await _roomServiceSender.SendRoomsMessages(arts);

                    amenityRoom.AmenityRoomId = Guid.NewGuid();
                    amenityRoom.RoomId        = arts.RoomId;

                    foreach (var amenity in apiRoom.Amenities)
                    {
                        amenityRoom.AmenityId = amenity.AmenityId;
                        await _complexRepository.CreateAmenityRoomAsync(amenityRoom);

                        _log.LogInformation("a list of amenities with room id: {0} was created", arts.RoomId);
                    }
                }

                return(StatusCode(201));
            }
            catch (Exception ex)
            {
                _log.LogError(ex, "error while creating room");
                return(StatusCode(500, ex.Message));
            }
        }
Beispiel #6
0
        public void AmenityRoomtoETest()
        {
            var arId   = Guid.NewGuid();
            var amId   = Guid.NewGuid();
            var rId    = Guid.NewGuid();
            var mapper = new Mapper();

            var ar = new Logic.AmenityRoom
            {
                AmenityRoomId = arId,
                AmenityId     = amId,
                RoomId        = rId
            };

            var eAr = mapper.MapAmenityRoomtoE(ar);

            Assert.Equal(arId, eAr.AmenityRoomId);
            Assert.Equal(amId, eAr.AmenityId);
            Assert.Equal(rId, eAr.RoomId);
        }
Beispiel #7
0
        //PUT: api/complex/editroom
        public async Task <ActionResult> PutRoomAsync([FromBody] ApiRoom apiRoom)
        {
            var arts        = new ApiRoomtoSend();
            var amenityRoom = new Logic.AmenityRoom();

            try
            {
                arts.RoomId       = apiRoom.RoomId;
                arts.RoomNumber   = apiRoom.RoomNumber;
                arts.ComplexId    = apiRoom.ComplexId;
                arts.NumberOfBeds = apiRoom.NumberOfBeds;
                arts.RoomType     = apiRoom.ApiRoomType;
                arts.LeaseStart   = apiRoom.LeaseStart;
                arts.LeaseEnd     = apiRoom.LeaseEnd;
                arts.QueOperator  = 2;

                amenityRoom.AmenityRoomId = Guid.NewGuid();
                amenityRoom.RoomId        = arts.RoomId;

                await _complexRepository.DeleteAmenityRoomAsync(apiRoom.RoomId);

                _log.LogInformation(")Amenity of Room Id {apiRoom.RoomId} is deleted", apiRoom.RoomId);

                await _roomServiceSender.SendRoomsMessages(arts);

                foreach (var amenity in apiRoom.Amenities)
                {
                    amenityRoom.AmenityId = amenity.AmenityId;
                    await _complexRepository.CreateAmenityRoomAsync(amenityRoom);

                    _log.LogInformation("list of amenity with room id: {arts.RoomId} is created", arts.RoomId);
                }

                return(StatusCode(200));
            }
            catch (Exception ex)
            {
                _log.LogError("{ex}: Internal Server Error", ex);
                return(StatusCode(500, ex.Message));
            }
        }