Exemplo n.º 1
0
        public static RoomTypes Map(RoomTypesViewModel roomTypes, IEnumerable <RoomType> dbRoomTypes)
        {
            var result = new RoomTypes();

            if (roomTypes == null)
            {
                return(result);
            }
            if (roomTypes.RoomTypes != null && roomTypes.RoomTypes.Any())
            {
                result.RoomTypeDescriptions = roomTypes.RoomTypes.Select(c => new RoomTypeDescription {
                    Description = c.Description, LowerBound = c.LowerBound, MarketBasePrice = c.MarketBasePrice, PeopleNum = c.PeopleNum, Number = (dbRoomTypes.FirstOrDefault(x => x.RoomTypeCode == c.RoomTypeCode)?.Id) ?? 0, OperationalCost = c.OperationalCost, Quantity = c.Quantity, UpperBound = c.UpperBound
                }).ToList();
            }
            if (roomTypes.ChildRoomTypes != null && roomTypes.ChildRoomTypes.Any())
            {
                result.ChildRooms = roomTypes.ChildRoomTypes.Select(c => new ChildRooms {
                    Child = (dbRoomTypes.FirstOrDefault(x => x.RoomTypeCode == c.Child)?.Id) ?? 0, Quantity = c.Quantity, Parent = (dbRoomTypes.FirstOrDefault(x => x.RoomTypeCode == c.Parent)?.Id) ?? 0
                }).ToList();
            }
            if (roomTypes.PriceConstraints != null && roomTypes.PriceConstraints.Any())
            {
                result.PriceConstraints = roomTypes.PriceConstraints.Select(c => new Hotels.Config.ConfigModel.PriceConstraint {
                    Less = (dbRoomTypes.FirstOrDefault(x => x.RoomTypeCode == c.Less)?.Id) ?? 0, More = (dbRoomTypes.FirstOrDefault(x => x.RoomTypeCode == c.More)?.Id) ?? 0
                }).ToList();
            }
            if (roomTypes.RoomTypeCoefs != null && roomTypes.RoomTypeCoefs.Any())
            {
                result.RoomTypeCoefs = roomTypes.RoomTypeCoefs.Select(c => new RoomTypeCoef {
                    Number = (dbRoomTypes.FirstOrDefault(x => x.RoomTypeCode == c.RoomTypeCode)?.Id) ?? 0, PeopleNum = c.PeopleNum, Coef = c.Coef
                }).ToList();
            }
            result.Total = result.RoomTypeDescriptions.Count();
            return(result);
        }
Exemplo n.º 2
0
        public static RoomTypesViewModel Map(RoomTypes roomTypes, IEnumerable <RoomType> dbRoomTypes)
        {
            var result = new RoomTypesViewModel();

            if (roomTypes == null)
            {
                return(result);
            }
            if (roomTypes.RoomTypeDescriptions != null && roomTypes.RoomTypeDescriptions.Any())
            {
                result.RoomTypes = roomTypes.RoomTypeDescriptions.Select(c => new RoomTypeViewModel {
                    Description = c.Description, PeopleNum = c.PeopleNum, LowerBound = c.LowerBound, MarketBasePrice = c.MarketBasePrice, Number = c.Number, OperationalCost = c.OperationalCost, Quantity = c.Quantity, UpperBound = c.UpperBound
                }).ToList();
            }
            var dict = dbRoomTypes.ToDictionary(c => c.Id, c => c.RoomTypeCode);

            if (roomTypes.RoomTypeCoefs != null && roomTypes.RoomTypeCoefs.Any())
            {
                result.RoomTypeCoefs.AddRange(roomTypes.RoomTypeCoefs.Where(c => dbRoomTypes.Any(s => s.Id == c.Number)).Select(c => new RoomTypeCoefViewModel {
                    RoomTypeCode = dict[c.Number], Coef = c.Coef, PeopleNum = c.PeopleNum
                }).ToList());
            }

            if (roomTypes.ChildRooms != null && roomTypes.ChildRooms.Any())
            {
                result.ChildRoomTypes = roomTypes.ChildRooms.Where(c => dbRoomTypes.Any(s => s.Id == c.Child) && dbRoomTypes.Any(s => s.Id == c.Parent)).Select(c => new ChildRoomTypeViewModel {
                    Child = dict[c.Child], Quantity = c.Quantity, Parent = dict[c.Parent]
                }).ToList();
            }
            if (roomTypes.PriceConstraints != null && roomTypes.PriceConstraints.Any())
            {
                result.PriceConstraints = roomTypes.PriceConstraints.Where(c => dbRoomTypes.Any(s => s.Id == c.Less) && dbRoomTypes.Any(s => s.Id == c.More)).Select(c => new PriceConstraint {
                    Less = dict[c.Less], More = dict[c.More]
                }).ToList();
            }

            foreach (var roomtype in dbRoomTypes)
            {
                var index = result.RoomTypes.FindIndex(c => c.Number == roomtype.Id);
                if (index >= 0)
                {
                    result.RoomTypes[index].Name         = roomtype.Name;
                    result.RoomTypes[index].RoomTypeCode = roomtype.RoomTypeCode;
                }
                else
                {
                    result.RoomTypes.Add(new RoomTypeViewModel {
                        Number = roomtype.Id, Name = roomtype.Name, RoomTypeCode = roomtype.RoomTypeCode
                    });
                }
            }
            return(result);
        }
Exemplo n.º 3
0
 public static ConfigurationRoot Map(ConfigurationViewModel config, IEnumerable <RoomType> roomTypes)
 {
     return(new ConfigurationRoot {
         Seasons = SeasonViewModel.Map(config.Seasons), Weekdays = WeekdaysViewModel.Map(config.Weekdays), RoomTypes = RoomTypesViewModel.Map(config.RoomTypes, roomTypes), MealTypes = MealTypesViewModel.Map(config.MealTypes), Categories = CategoriesViewModel.Map(config.Categories)
     });
 }