Exemple #1
0
        /// <summary>
        /// Save and update the room facilities
        /// </summary>
        /// <param name="hotelFacilityViewModel">hotel Facility View Model</param>
        /// <returns>long</returns>
        public async Task <BaseResult <long> > InsertAndUpdateRoomFacilityRelation(RoomFacilityGroupListViewModel roomFacilityViewModel, string userName)
        {
            BaseResult <long> result = new BaseResult <long>();

            foreach (var item in roomFacilityViewModel.FacilityGroupList)
            {
                foreach (var facilityType in item.RoomFacilityTypes)
                {
                    foreach (var facility in facilityType.FacilityList)
                    {
                        if (facility.ObjectState == ObjectState.Added)
                        {
                            result = await AddRoomFacilityRelation(facility, userName, roomFacilityViewModel.HotelId);

                            continue;
                        }
                        if (facility.ObjectState == ObjectState.Deleted)
                        {
                            result = await DeleteRoomFacilityRelation(facility, userName);

                            continue;
                        }
                        if (facility.ObjectState == ObjectState.Unchanged)
                        {
                            result = await UnchangedRoomFacilityRelation(facility, userName, roomFacilityViewModel.HotelId);

                            continue;
                        }
                    }
                }
            }
            return(result);
        }
Exemple #2
0
        public async Task <IActionResult> CreateRoomFacilityRelation([FromBody] RoomFacilityGroupListViewModel roomFacilityViewModel)
        {
            BaseResult <long> result = new BaseResult <long>();

            if (roomFacilityViewModel != null)
            {
                var validateResponse = ValidateCreateRoomFacilityRelationRequest(roomFacilityViewModel);
                if (validateResponse.Message != null)
                {
                    return(this.BadRequest(validateResponse));
                }
                result = await this.iAmenities.InsertAndUpdateRoomFacilityRelation(roomFacilityViewModel, base.LoggedInUserName);

                if (result.Message != null)
                {
                    return(this.BadRequest(result));
                }
                if (result.IsError || result.ExceptionMessage != null)
                {
                    return(StatusCode(500, result));
                }
                return(this.Ok(result)); //200
            }
            else
            {
                return(this.BadRequest(result));
            }
        }
        public async Task TestCreateRoomFacilityRelation_Failed_BadRequest()
        {
            //Arrange
            RoomFacilityGroupListViewModel roomFacilities = null;
            //Act
            var result = await mockAmenitiesController.CreateRoomFacilityRelation(roomFacilities);

            //Assert
            Assert.AreEqual(((BadRequestObjectResult)result).StatusCode, 400);
        }
        public async Task TestCreateRoomFacilityRelationEdit_SuccessOkResponse()
        {
            var id = 1;
            //Arrange
            RoomFacilityGroupListViewModel roomFacilities = new RoomFacilityGroupListViewModel()
            {
                HotelId     = 1,
                ObjectState = ObjectState.Added,
            };
            RoomFacilityGroupViewModel facilityGroup = new RoomFacilityGroupViewModel()
            {
                Id   = 1,
                Name = "Group1",
            };
            RoomFacilityTypeViewModel facilityType = new RoomFacilityTypeViewModel()
            {
                FacilityGroupId = 1,
            };
            RoomFacilityViewModel facility = new RoomFacilityViewModel()
            {
                Id              = 1,
                Name            = "facility1",
                ObjectState     = ObjectState.Deleted,
                FacilityGroupId = 1,
                IsSelected      = true
            };
            FacilitiesRoomList facilityRoom = new FacilitiesRoomList()
            {
                RoomTypeId  = 1,
                RoomName    = "Room1",
                IsSelected  = true,
                ObjectState = ObjectState.Deleted
            };

            facility.FacilitiesRoomList.Add(facilityRoom);
            facilityType.FacilityList.Add(facility);
            facilityGroup.RoomFacilityTypes.Add(facilityType);
            roomFacilities.FacilityGroupList.Add(facilityGroup);
            mockAmenitiesRepository.Setup(a => a.InsertAndUpdateRoomFacilityRelation(It.IsAny <RoomFacilityGroupListViewModel>(), It.IsAny <string>())).Returns(Task.FromResult(new BaseResult <long>()
            {
                Result = 1
            }));
            //Act
            IActionResult result = await mockAmenitiesController.CreateRoomFacilityRelation(roomFacilities);

            BaseResult <long> finalResult = (result as Microsoft.AspNetCore.Mvc.OkObjectResult).Value as BaseResult <long>;

            //Assert
            Assert.AreEqual(((Microsoft.AspNetCore.Mvc.ObjectResult)result).StatusCode, 200);
            Assert.IsNotNull(finalResult);
            Assert.IsTrue(!finalResult.IsError);
            Assert.IsTrue(finalResult.Result == id);
        }
        public void TestInsertAndUpdateRoomFacilityRelation_SaveRoomFacilities_Success()
        {
            var    id       = 1;
            string userName = "******";

            //Arrange
            RoomFacilityGroupListViewModel roomFacilities = new RoomFacilityGroupListViewModel()
            {
                HotelId     = 1,
                ObjectState = ObjectState.Added,
            };
            RoomFacilityGroupViewModel facilityGroup = new RoomFacilityGroupViewModel()
            {
                Id   = 1,
                Name = "Group1",
            };
            RoomFacilityTypeViewModel facilityType = new RoomFacilityTypeViewModel()
            {
                FacilityGroupId = 1,
            };
            RoomFacilityViewModel facility = new RoomFacilityViewModel()
            {
                Id              = 1,
                Name            = "facility1",
                ObjectState     = ObjectState.Added,
                FacilityGroupId = 1,
                IsSelected      = true
            };
            FacilitiesRoomList facilityRoom = new FacilitiesRoomList()
            {
                RoomTypeId  = 1,
                RoomName    = "Room1",
                IsSelected  = true,
                ObjectState = ObjectState.Added
            };

            facility.FacilitiesRoomList.Add(facilityRoom);
            facilityType.FacilityList.Add(facility);
            facilityGroup.RoomFacilityTypes.Add(facilityType);
            roomFacilities.FacilityGroupList.Add(facilityGroup);
            iRoomFacilityRelationLibrary.Setup(a => a.InsertEntityList(It.IsAny <List <RoomFacilityRelation> >())).Returns(Task.FromResult(new BaseResult <long>()
            {
                Result = id
            })).Verifiable();
            //Act
            var result = amenitiesRepository.InsertAndUpdateRoomFacilityRelation(roomFacilities, userName);

            //Assert
            iRoomFacilityTypeLibrary.Verify();
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Result.Result == id);
        }
        public async Task TestCreateRoomFacilityRelation_Failed_Error()
        {
            //Arrange
            RoomFacilityGroupListViewModel roomFacilities = new RoomFacilityGroupListViewModel()
            {
                HotelId     = 1,
                ObjectState = ObjectState.Added,
            };
            RoomFacilityGroupViewModel facilityGroup = new RoomFacilityGroupViewModel()
            {
                Id   = 1,
                Name = "Group1",
            };
            RoomFacilityTypeViewModel facilityType = new RoomFacilityTypeViewModel()
            {
                FacilityGroupId = 1,
            };
            RoomFacilityViewModel facility = new RoomFacilityViewModel()
            {
                Id   = 1,
                Name = "facility1",
            };
            FacilitiesRoomList facilityRoom = new FacilitiesRoomList()
            {
                RoomTypeId = 1,
                RoomName   = "Room1",
                IsSelected = true,
            };

            facility.FacilitiesRoomList.Add(facilityRoom);
            facilityType.FacilityList.Add(facility);
            facilityGroup.RoomFacilityTypes.Add(facilityType);
            roomFacilities.FacilityGroupList.Add(facilityGroup);
            mockAmenitiesRepository.Setup(a => a.InsertAndUpdateRoomFacilityRelation(It.IsAny <RoomFacilityGroupListViewModel>(), It.IsAny <string>())).Returns(Task.FromResult(new BaseResult <long>()
            {
                IsError          = true,
                ExceptionMessage = Helper.Common.GetMockException(),
            })).Verifiable();
            //Act

            IActionResult result = await mockAmenitiesController.CreateRoomFacilityRelation(roomFacilities);

            //Assert
            mockAmenitiesRepository.Verify();
            Assert.AreEqual(((Microsoft.AspNetCore.Mvc.ObjectResult)result).StatusCode, 500);
        }
        public async Task TestCreateRoomFacilityRelation_Failed_BadRequest1()
        {
            //Arrange
            RoomFacilityGroupListViewModel roomFacilities = new RoomFacilityGroupListViewModel()
            {
                HotelId     = 1,
                ObjectState = ObjectState.Added,
            };
            RoomFacilityGroupViewModel facilityGroup = new RoomFacilityGroupViewModel()
            {
                Id   = 1,
                Name = "Group1",
            };
            RoomFacilityTypeViewModel facilityType = new RoomFacilityTypeViewModel()
            {
                FacilityGroupId = 1,
            };
            RoomFacilityViewModel facility = new RoomFacilityViewModel()
            {
                Id   = 1,
                Name = "facility1",
            };
            FacilitiesRoomList facilityRoom = null;

            facility.FacilitiesRoomList.Add(facilityRoom);
            facilityType.FacilityList.Add(facility);
            facilityGroup.RoomFacilityTypes.Add(facilityType);
            roomFacilities.FacilityGroupList.Add(facilityGroup);
            mockAmenitiesRepository.Setup(a => a.InsertAndUpdateRoomFacilityRelation(It.IsAny <RoomFacilityGroupListViewModel>(), It.IsAny <string>())).Returns(Task.FromResult(new BaseResult <long>()
            {
                Message = "Room must be selected"
            }));
            //Act
            var result = await mockAmenitiesController.CreateRoomFacilityRelation(roomFacilities);

            //Assert
            Assert.AreEqual(((BadRequestObjectResult)result).StatusCode, 400);
        }
Exemple #8
0
        /// <summary>
        /// Validation for Save and update request
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private BaseResult <bool> ValidateCreateRoomFacilityRelationRequest(RoomFacilityGroupListViewModel request)
        {
            BaseResult <bool> validationResponse = new BaseResult <bool>()
            {
                Result = true
            };

            foreach (var item in request.FacilityGroupList)
            {
                foreach (var facilityType in item.RoomFacilityTypes)
                {
                    foreach (var facility in facilityType.FacilityList)
                    {
                        if (facility.FacilitiesRoomList.Any())
                        {
                            if (facility.IsSelected == true)
                            {
                                var count = facility.FacilitiesRoomList.Count(a => a.IsSelected == true);
                                if (count < 0)
                                {
                                    validationResponse.Result  = false;
                                    validationResponse.Message = Constants.ErrorMessage.RoomsForSelectedAmenitiesMissing;
                                    return(validationResponse);
                                }
                            }
                        }
                        else
                        {
                            validationResponse.Result  = false;
                            validationResponse.Message = Constants.ErrorMessage.NoRooms;
                            return(validationResponse);
                        }
                    }
                }
            }
            return(validationResponse);
        }
        public void TestInsertAndUpdateRoomFacilityRelation_DeleteRoomFacilities_Success()
        {
            var    id       = 1;
            string userName = "******";
            //Arrange
            RoomFacilityGroupListViewModel roomFacilities = new RoomFacilityGroupListViewModel()
            {
                HotelId     = 1,
                ObjectState = ObjectState.Added,
            };
            RoomFacilityGroupViewModel facilityGroup = new RoomFacilityGroupViewModel()
            {
                Id   = 1,
                Name = "Group1",
            };
            RoomFacilityTypeViewModel facilityType = new RoomFacilityTypeViewModel()
            {
                FacilityGroupId = 1,
            };
            RoomFacilityViewModel facility = new RoomFacilityViewModel()
            {
                Id              = 1,
                Name            = "facility1",
                ObjectState     = ObjectState.Deleted,
                FacilityGroupId = 1,
                IsSelected      = true
            };
            FacilitiesRoomList facilityRoom = new FacilitiesRoomList()
            {
                RoomTypeId  = 1,
                RoomName    = "Room1",
                IsSelected  = true,
                ObjectState = ObjectState.Unchanged
            };

            facility.FacilitiesRoomList.Add(facilityRoom);
            facilityType.FacilityList.Add(facility);
            facilityGroup.RoomFacilityTypes.Add(facilityType);
            roomFacilities.FacilityGroupList.Add(facilityGroup);
            iRoomFacilityRelationLibrary.Setup(a => a.UpdateEntityList(It.IsAny <List <RoomFacilityRelation> >())).Returns(Task.FromResult(new BaseResult <bool>()
            {
                Result = true
            })).Verifiable();
            var baseResult = new BaseResult <List <RoomFacilityRelation> >()
            {
                Result = new List <RoomFacilityRelation>()
                {
                    new RoomFacilityRelation()
                    {
                        Id = 1, IsDeleted = false, FacilityId = 1
                    }
                }
            };
            var pred = new Func <RoomFacilityRelation, bool>(x => x.FacilityId == id && x.IsDeleted == false);

            iRoomFacilityRelationLibrary.Setup(a => a.GetListByPredicate(It.Is <Func <RoomFacilityRelation, bool> >(x => x.GetType() == pred.GetType()))).Returns(Task.FromResult(baseResult)).Verifiable();
            //Act
            var result = amenitiesRepository.InsertAndUpdateRoomFacilityRelation(roomFacilities, userName);

            //Assert
            iRoomFacilityTypeLibrary.Verify();
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Result.Result == 1);
        }