예제 #1
0
        /// <summary>
        /// Map ChildrenAndExtraBedPolicies
        /// </summary>
        /// <param name="childrenAndExtraBedPoliciesViewModel"></param>
        /// <param name="isActive"></param>
        /// <param name="isDeleted"></param>
        /// <returns></returns>
        public static void MapChildAndExtraBedPolicy(ref ChildrenAndExtraBedPolicies childrenAndExtraBedPoliciesResult, ref List <Room> roomListResult, List <Room> roomList, ChildrenAndExtraBedPoliciesViewModel childrenAndExtraBedPoliciesViewModel, string userName)
        {
            childrenAndExtraBedPoliciesResult = new ChildrenAndExtraBedPolicies();

            childrenAndExtraBedPoliciesResult.Id = childrenAndExtraBedPoliciesViewModel.Id;
            childrenAndExtraBedPoliciesResult.IsChildrenAllowed = childrenAndExtraBedPoliciesViewModel.IsChildrenAllowed;
            childrenAndExtraBedPoliciesResult.MinChildAge       = childrenAndExtraBedPoliciesViewModel.MinChildAge;
            childrenAndExtraBedPoliciesResult.MaxChildAge       = childrenAndExtraBedPoliciesViewModel.MaxChildAge;
            childrenAndExtraBedPoliciesResult.IsExtraCotAllowed = childrenAndExtraBedPoliciesViewModel.IsExtraCotAllowed;
            childrenAndExtraBedPoliciesResult.IsExtraBedAllowed = childrenAndExtraBedPoliciesViewModel.IsExtraBedAllowed;
            childrenAndExtraBedPoliciesResult.MinInfantAge      = childrenAndExtraBedPoliciesViewModel.MinInfantAge;
            childrenAndExtraBedPoliciesResult.MaxInfantAge      = childrenAndExtraBedPoliciesViewModel.MaxInfantAge;
            childrenAndExtraBedPoliciesResult.CotPrice          = childrenAndExtraBedPoliciesViewModel.CotPrice;
            childrenAndExtraBedPoliciesResult.CotPriceTypeId    = childrenAndExtraBedPoliciesViewModel.CotPriceTypeId; //(childrenAndExtraBedPoliciesViewModel.CotPriceTypeId==null)? 1: childrenAndExtraBedPoliciesViewModel.CotPriceTypeId.Value;
            childrenAndExtraBedPoliciesResult.HotelId           = childrenAndExtraBedPoliciesViewModel.HotelId;
            childrenAndExtraBedPoliciesResult.IsActive          = true;
            childrenAndExtraBedPoliciesResult.IsDeleted         = false;

            foreach (var item in childrenAndExtraBedPoliciesViewModel.MaxChildAndExtraBedPerRoomList)
            {
                foreach (var room in roomList)
                {
                    if (room.Id == item.RoomId && item.ObjectState == ObjectState.Modified)//
                    {
                        room.ExtraBedCount = item.ExtraBedCount;
                        room.CreatedBy     = userName;
                        room.UpdatedBy     = userName;
                        room.MaxChildren   = item.MaxChildren;
                        roomListResult.Add(room);
                    }
                }
            }
        }
예제 #2
0
        public async Task TestCreateChildrenAndExtraBedPolicy_Success_OkResponse()
        {
            //Arrange
            List <Room> roomList = new List <Room>();
            MaxChildAndExtraBedPerRoomViewModel maxChildAndExtraBedPerRoomModel = new MaxChildAndExtraBedPerRoomViewModel()
            {
                HotelId       = 5,
                RoomId        = 332,
                RoomName      = "Large",
                BedCount      = 2,
                ExtraBedCount = 1,
                MaxChildren   = 2,
                NoOfGuest     = 4
            };
            ChildrenAndExtraBedPoliciesViewModel childrenAndExtraBedPoliciesViewModel = new ChildrenAndExtraBedPoliciesViewModel()
            {
                HotelId           = 5,
                IsChildrenAllowed = true,
                MinChildAge       = 0,
                MaxChildAge       = 4,
                IsExtraCotAllowed = true,
                MinInfantAge      = 2,
                MaxInfantAge      = 5,
                IsExtraBedAllowed = true,
                CotPrice          = 1000,
                CotPriceTypeId    = 2,
            };
            ChildrenAndExtraBedPolicies childrenAndExtraBedPoliciesModel = new ChildrenAndExtraBedPolicies();

            childrenAndExtraBedPoliciesViewModel.ObjectState = ObjectState.Added;
            childrenAndExtraBedPoliciesViewModel.MaxChildAndExtraBedPerRoomList.Add(maxChildAndExtraBedPerRoomModel);
            ObjectState objectState = ObjectState.Added;

            mockPoliciesRepository.Setup(x => x.GetRoomsById(It.IsAny <List <MaxChildAndExtraBedPerRoomViewModel> >())).Returns(Task.FromResult(new BaseResult <List <Room> >()
            {
                Result = roomList
            })).Verifiable();
            mockPoliciesRepository.Setup(a => a.SaveAndUpdateChildAndExtraBedPolicy(It.IsAny <ChildrenAndExtraBedPolicies>(), objectState)).Returns(Task.FromResult(new BaseResult <ChildrenAndExtraBedPolicies> {
                Result = new ChildrenAndExtraBedPolicies()
            }));
            mockPoliciesRepository.Setup(a => a.SaveAndUpdateChildAndExtraBedPolicy(It.IsAny <ChildrenAndExtraBedPolicies>(), objectState)).Returns(Task.FromResult(new BaseResult <ChildrenAndExtraBedPolicies> {
                Result = childrenAndExtraBedPoliciesModel
            })).Verifiable();
            mockPoliciesRepository.Setup(a => a.UpdateRoomList(It.IsAny <List <Room> >())).Returns(Task.FromResult(new BaseResult <bool> {
                Result = true
            })).Verifiable();

            //Act
            Task <IActionResult> actionResult = mockPoliciesController.CreateChildrenAndExtraBedPolicy(childrenAndExtraBedPoliciesViewModel);

            //Assert
            BaseResult <ChildrenAndExtraBedPolicies> saveOrUpdatechildrenAndExtraBedPolicies = (actionResult.Result as Microsoft.AspNetCore.Mvc.OkObjectResult).Value as BaseResult <ChildrenAndExtraBedPolicies>;

            Assert.AreEqual(((Microsoft.AspNetCore.Mvc.ObjectResult)actionResult.Result).StatusCode, 200);
            Assert.IsNotNull(saveOrUpdatechildrenAndExtraBedPolicies);
            Assert.IsTrue(saveOrUpdatechildrenAndExtraBedPolicies.Result != null);
        }
예제 #3
0
        //[ValidateModel]
        public async Task <IActionResult> CreateChildrenAndExtraBedPolicy([FromBody] ChildrenAndExtraBedPoliciesViewModel ChildrenAndExtraBedPoliciesViewModel)
        {
            ChildrenAndExtraBedPolicies childrenAndExtraBedPoliciesResult = null;
            string userName = base.LoggedInUserName;

            if (ChildrenAndExtraBedPoliciesViewModel != null && ChildrenAndExtraBedPoliciesViewModel.HotelId > default(int))
            {
                //Fetch list of room by id
                List <Room> roomListResult = new List <Room>();
                var         maxChildAndExtraBedPerRoomList = ChildrenAndExtraBedPoliciesViewModel.MaxChildAndExtraBedPerRoomList;
                BaseResult <List <Room> > roomsResult      = await iPolicies.GetRoomsById(ChildrenAndExtraBedPoliciesViewModel.MaxChildAndExtraBedPerRoomList).ConfigureAwait(false);

                if (roomsResult.IsError && roomsResult.ExceptionMessage != null)
                {
                    return(new StatusCodeResult(500));
                }
                var roomList = roomsResult.Result;

                //Map and retrieve childrenAndExtraBedPolicy and updated roomlist
                PoliciesRequestMapper.MapChildAndExtraBedPolicy(ref childrenAndExtraBedPoliciesResult, ref roomListResult, roomList, ChildrenAndExtraBedPoliciesViewModel, userName);

                //Save or Update Child and Extra Bed Policy
                BaseResult <ChildrenAndExtraBedPolicies> addOrUpdateChildrenAndExtraBedPoliciesResult = await iPolicies.SaveAndUpdateChildAndExtraBedPolicy(childrenAndExtraBedPoliciesResult, ChildrenAndExtraBedPoliciesViewModel.ObjectState).ConfigureAwait(false);

                if (addOrUpdateChildrenAndExtraBedPoliciesResult.IsError && addOrUpdateChildrenAndExtraBedPoliciesResult.ExceptionMessage != null)
                {
                    return(new StatusCodeResult(500));
                }
                else if (addOrUpdateChildrenAndExtraBedPoliciesResult.Result == null)
                {
                    return(new NoContentResult());
                }
                else if (addOrUpdateChildrenAndExtraBedPoliciesResult.Message != null)
                {
                    return(BadRequest(addOrUpdateChildrenAndExtraBedPoliciesResult));
                }
                //update list of room
                if (roomListResult.Count > 0)
                {
                    BaseResult <bool> updateRoomListResult = await iPolicies.UpdateRoomList(roomListResult).ConfigureAwait(false);

                    if (updateRoomListResult.IsError && updateRoomListResult.ExceptionMessage != null)
                    {
                        return(new StatusCodeResult(500));
                    }
                    else if (!updateRoomListResult.Result)
                    {
                        return(new NotFoundResult());//404
                    }
                }
                return(Ok(addOrUpdateChildrenAndExtraBedPoliciesResult));
            }

            return(BadRequest());//400
        }
        public async Task TestSaveAndUpdateChildAndExtraBedPolicy_Update_Failed_Error()
        {
            //Arrange
            ObjectState objectState = ObjectState.Modified;
            var         childrenAndExtraBedPoliciesModel = new ChildrenAndExtraBedPolicies()
            {
                Id                = 1,
                IsActive          = true,
                IsChildrenAllowed = true,
                IsExtraCotAllowed = true,
                IsExtraBedAllowed = true,
                CotPrice          = 1000,
                CotPriceTypeId    = 2,
                HotelId           = 5,
                MinChildAge       = 0,
                MaxChildAge       = 5,
                MinInfantAge      = 2,
                MaxInfantAge      = 5,
                IsDeleted         = false
            };
            var childrenAndExtraBedPoliciesModelList = new List <ChildrenAndExtraBedPolicies>();

            childrenAndExtraBedPoliciesModelList.Add(childrenAndExtraBedPoliciesModel);
            var baseResult = new BaseResult <List <ChildrenAndExtraBedPolicies> >()
            {
                Result = childrenAndExtraBedPoliciesModelList
            };
            var pred = new Func <ChildrenAndExtraBedPolicies, bool>(x => x.HotelId == 5 && x.IsActive);

            iChildrenAndExtraBedPoliciesConnectionLibrary.Setup(x => x.GetListByPredicate(It.Is <Func <ChildrenAndExtraBedPolicies, bool> >(y => y.GetType() == pred.GetType()))).Returns(Task.FromResult(baseResult));

            iChildrenAndExtraBedPoliciesConnectionLibrary.Setup(x => x.UpdateEntityByDapper(It.IsAny <ChildrenAndExtraBedPolicies>())).Returns(Task.FromResult(new BaseResult <bool>()
            {
                IsError          = true,
                ExceptionMessage = Helper.Common.GetMockException()
            })).Verifiable();


            //Act
            Task <BaseResult <ChildrenAndExtraBedPolicies> > actionResult = policiesRepository.SaveAndUpdateChildAndExtraBedPolicy(childrenAndExtraBedPoliciesModel, objectState);

            //Assert
            Assert.IsTrue(actionResult.Result.IsError);
            Assert.IsTrue(actionResult.Result.ExceptionMessage != null);
        }
        public async Task TestSaveAndUpdateChildAndExtraBedPolicy_Save_Passed_Success()
        {
            //Arrange
            ChildrenAndExtraBedPolicies childrenAndExtraBedPoliciesModel = new ChildrenAndExtraBedPolicies();
            ObjectState objectState = ObjectState.Added;

            iChildrenAndExtraBedPoliciesConnectionLibrary.Setup(x => x.InsertEntity(It.IsAny <ChildrenAndExtraBedPolicies>())).Returns(Task.FromResult(new BaseResult <long>()
            {
                Result = 3
            }));

            //Act
            Task <BaseResult <ChildrenAndExtraBedPolicies> > actionResult = policiesRepository.SaveAndUpdateChildAndExtraBedPolicy(childrenAndExtraBedPoliciesModel, objectState);

            //Assert
            Assert.IsTrue(actionResult != null);
            Assert.IsTrue(actionResult.Result != null);
            Assert.IsTrue(!actionResult.Result.IsError);
        }
        public async Task TestSaveAndUpdateChildAndExtraBedPolicy_Save_Failed_Error()
        {
            //Arrange
            ChildrenAndExtraBedPolicies childrenAndExtraBedPoliciesModel = new ChildrenAndExtraBedPolicies();
            ObjectState objectState = ObjectState.Added;

            iChildrenAndExtraBedPoliciesConnectionLibrary.Setup(x => x.InsertEntity(It.IsAny <ChildrenAndExtraBedPolicies>())).Returns(Task.FromResult(new BaseResult <long>()
            {
                IsError          = true,
                ExceptionMessage = Helper.Common.GetMockException()
            })).Verifiable();

            //Act
            Task <BaseResult <ChildrenAndExtraBedPolicies> > actionResult = policiesRepository.SaveAndUpdateChildAndExtraBedPolicy(childrenAndExtraBedPoliciesModel, objectState);

            //Assert
            Assert.IsTrue(actionResult.Result.IsError);
            Assert.IsTrue(actionResult.Result.ExceptionMessage != null);
        }
        public async Task TestGetChildrenAndExtraBedPolicyListingByHotelId_positive_Predicate_sample()
        {
            //Arrange
            int hotelId = 5;
            var childrenAndExtraBedPolicy = new ChildrenAndExtraBedPolicies();

            var baseResult = new BaseResult <List <ChildrenAndExtraBedPolicies> >()
            {
                Result = new List <ChildrenAndExtraBedPolicies>()
                {
                    childrenAndExtraBedPolicy
                }
            };
            var pred = new Func <ChildrenAndExtraBedPolicies, bool>(x => x.HotelId == hotelId && x.IsActive && !x.IsDeleted);

            iChildrenAndExtraBedPoliciesConnectionLibrary.Setup(x => x.GetListByPredicate(It.Is <Func <ChildrenAndExtraBedPolicies, bool> >(y => y.GetType() == pred.GetType()))).Returns(Task.FromResult(baseResult));
            //Act
            Task <BaseResult <List <ChildrenAndExtraBedPolicies> > > result = policiesRepository.GetChildrenAndExtraBedPolicyListingByHotelId(hotelId);

            //Assert
            Assert.IsTrue(result.Result != null);
            Assert.IsTrue(result.Result is BaseResult <List <ChildrenAndExtraBedPolicies> >);
        }
예제 #8
0
        /// <summary>
        /// Creates new hotel meal or edits the hotel meal
        /// </summary>
        /// <param name="hotelMealRequest"></param>
        /// <param name="objectState"></param>
        /// <param name="userName"></param>
        /// <returns>Task<BaseResult<long>></returns>
        public async Task <BaseResult <ChildrenAndExtraBedPolicies> > SaveAndUpdateChildAndExtraBedPolicy(ChildrenAndExtraBedPolicies childrenAndExtraBedPoliciesRequest, ObjectState?objectState)
        {
            BaseResult <ChildrenAndExtraBedPolicies> result = new BaseResult <ChildrenAndExtraBedPolicies>();

            result.Result = new ChildrenAndExtraBedPolicies();
            if (objectState == ObjectState.Added)
            {
                var insertResult = await iChildrenAndExtraBedPoliciesConnectionLibrary.InsertEntity(childrenAndExtraBedPoliciesRequest).ConfigureAwait(false);

                if (insertResult == null)
                {
                    return(result = null);
                }
                else if (insertResult.IsError || insertResult.ExceptionMessage != null)
                {
                    result.IsError          = true;
                    result.ExceptionMessage = insertResult.ExceptionMessage;
                    return(result);
                }

                result.Result.Id = (int)insertResult.Result;
                return(result);
            }
            else if (objectState == ObjectState.Modified)
            {
                var childrenAndExtraBedPoliciesResult = await iChildrenAndExtraBedPoliciesConnectionLibrary.GetListByPredicate(x => x.HotelId == childrenAndExtraBedPoliciesRequest.HotelId && x.IsActive).ConfigureAwait(false);

                if (childrenAndExtraBedPoliciesResult.Result.Count > 0 && childrenAndExtraBedPoliciesResult != null)
                {
                    var updatedChildrenAndExtraBedPolicy = PoliciesRequestMapper.AutoMapperChildrenAndExtraBedPolicy(childrenAndExtraBedPoliciesRequest, childrenAndExtraBedPoliciesResult.Result.First());

                    var updateResult = await iChildrenAndExtraBedPoliciesConnectionLibrary.UpdateEntityByDapper(updatedChildrenAndExtraBedPolicy).ConfigureAwait(false);

                    if (updateResult == null)
                    {
                        return(result = null);
                    }
                    else if (updateResult.IsError || updateResult.ExceptionMessage != null)
                    {
                        result.IsError          = true;
                        result.ExceptionMessage = updateResult.ExceptionMessage;
                        return(result);
                    }
                    else if (updateResult.Result)
                    {
                        result.Result.Id = childrenAndExtraBedPoliciesRequest.Id;
                    }
                    return(result);
                }
                else
                {
                    result.IsError   = true;
                    result.ErrorCode = (int)coreHelper.Constants.ErrorCodes.NoChildrenAndExtraBedPolicyOfID;
                    result.Message   = string.Format(coreHelper.Constants.ErrorMessage.NoChildrenAndExtraBedPolicyOfID, childrenAndExtraBedPoliciesRequest.Id);
                    return(result);
                }
            }
            return(result);
        }
예제 #9
0
 /// <summary>
 /// Resolve remaining parameters
 /// </summary>
 /// <param name="destination"></param>
 /// <param name="source"></param>
 public static void ResolveRemainingParamtersChildrenAndExtraBedPolicy(ChildrenAndExtraBedPolicies destination, ChildrenAndExtraBedPolicies source)
 {
     destination.Id        = source.Id;
     destination.IsDeleted = source.IsDeleted;
 }
예제 #10
0
        /// <summary>
        /// Maps view model of hotelmeal to hotelmeal model
        /// </summary>
        /// <param name="childrenAndExtraBedPoliciesToMap"></param>
        /// <param name="hotelMealDatabase"></param>
        /// <param name="userName"></param>
        /// <returns>Message</returns>
        public static ChildrenAndExtraBedPolicies AutoMapperChildrenAndExtraBedPolicy(ChildrenAndExtraBedPolicies childrenAndExtraBedPolicyToMap, ChildrenAndExtraBedPolicies childrenAndExtraBedPolicyDatabase)
        {
            var childrenAndExtraBedPolicyMapped = AutoMapper.Mapper.Map <ChildrenAndExtraBedPolicies>(childrenAndExtraBedPolicyToMap);

            ResolveRemainingParamtersChildrenAndExtraBedPolicy(childrenAndExtraBedPolicyToMap, childrenAndExtraBedPolicyDatabase);
            return(childrenAndExtraBedPolicyMapped);
        }
예제 #11
0
        public async Task TestCreateChildrenAndExtraBedPolicy_Exception_ByUpdateRoomList_InternalServerError()
        {
            //Arrange
            List <Room> roomList = new List <Room>();
            Room        room     = new Room()
            {
                HotelId       = 5,
                Id            = 332,
                Name          = "Large",
                ExtraBedCount = 1,
                MaxChildren   = 2
            };

            roomList.Add(room);
            MaxChildAndExtraBedPerRoomViewModel maxChildAndExtraBedPerRoomModel = new MaxChildAndExtraBedPerRoomViewModel()
            {
                HotelId       = 5,
                RoomId        = 332,
                RoomName      = "Large",
                BedCount      = 2,
                ExtraBedCount = 1,
                MaxChildren   = 2,
                NoOfGuest     = 4,
            };

            maxChildAndExtraBedPerRoomModel.ObjectState = ObjectState.Modified;
            ChildrenAndExtraBedPoliciesViewModel childrenAndExtraBedPoliciesViewModel = new ChildrenAndExtraBedPoliciesViewModel()
            {
                HotelId           = 5,
                IsChildrenAllowed = true,
                MinChildAge       = 0,
                MaxChildAge       = 4,
                IsExtraCotAllowed = true,
                MinInfantAge      = 2,
                MaxInfantAge      = 5,
                IsExtraBedAllowed = true,
                CotPrice          = 1000,
                CotPriceTypeId    = 2,
            };
            ChildrenAndExtraBedPolicies childrenAndExtraBedPoliciesModel = new ChildrenAndExtraBedPolicies();

            childrenAndExtraBedPoliciesViewModel.ObjectState = ObjectState.Added;
            childrenAndExtraBedPoliciesViewModel.MaxChildAndExtraBedPerRoomList.Add(maxChildAndExtraBedPerRoomModel);
            ObjectState objectState = ObjectState.Added;

            mockPoliciesRepository.Setup(x => x.GetRoomsById(It.IsAny <List <MaxChildAndExtraBedPerRoomViewModel> >())).Returns(Task.FromResult(new BaseResult <List <Room> >()
            {
                Result = roomList
            })).Verifiable();
            mockPoliciesRepository.Setup(a => a.SaveAndUpdateChildAndExtraBedPolicy(It.IsAny <ChildrenAndExtraBedPolicies>(), objectState)).Returns(Task.FromResult(new BaseResult <ChildrenAndExtraBedPolicies> {
                Result = new ChildrenAndExtraBedPolicies()
            }));
            mockPoliciesRepository.Setup(a => a.SaveAndUpdateChildAndExtraBedPolicy(It.IsAny <ChildrenAndExtraBedPolicies>(), objectState)).Returns(Task.FromResult(new BaseResult <ChildrenAndExtraBedPolicies> {
                Result = childrenAndExtraBedPoliciesModel
            })).Verifiable();
            mockPoliciesRepository.Setup(x => x.UpdateRoomList(It.IsAny <List <Room> >())).Returns(Task.FromResult(new BaseResult <bool>()
            {
                IsError          = true,
                ExceptionMessage = Helper.Common.GetMockException()
            })).Verifiable();
            //Act
            Task <IActionResult> actionResult = mockPoliciesController.CreateChildrenAndExtraBedPolicy(childrenAndExtraBedPoliciesViewModel);

            //Assert
            Assert.IsTrue(actionResult != null);
            Assert.AreEqual(((Microsoft.AspNetCore.Mvc.StatusCodeResult)actionResult.Result).StatusCode, 500);
        }