예제 #1
0
        public HotelDto CreateHotel(HotelDto hotelDto, int userId, int tenantId, List <MemoryStream> files, string path)
        {
            if (GetHotel(hotelDto.HotelId, tenantId) != null)
            {
                return(EditHotel(hotelDto, userId, tenantId, files, path, 1));
            }
            ValidateHotel(hotelDto, tenantId);
            var hotelObj = Mapper.Map <Hotel>(hotelDto);

            foreach (var hotelName in hotelDto.TitleDictionary)
            {
                hotelObj.HotelTranslations.Add(new HotelTranslation
                {
                    Title       = hotelName.Value,
                    Description = hotelDto.DescriptionDictionary[hotelName.Key],
                    Language    = hotelName.Key,
                });
            }

            hotelObj.TenantId      = tenantId;
            hotelObj.CityId        = hotelDto.CityId;
            hotelObj.Latitude      = hotelDto.Latitude;
            hotelObj.Longitude     = hotelDto.Longitude;
            hotelObj.Star          = hotelDto.Star;
            hotelObj.CreationTime  = Strings.CurrentDateTime;
            hotelObj.CreatorUserId = userId;
            hotelObj.CurrencyId    = hotelDto.CurrencyId;


            //foreach (var roleper in hotelDto.HotelFeature)
            //{
            //    hotelObj.HotelFeature.Add(new HotelFeature
            //    {
            //        FeatureId = roleper.FeatureId
            //    });
            //}
            _hotelFeatureService.InsertRange(hotelObj.HotelFeature);

            _hotelTranslationService.InsertRange(hotelObj.HotelTranslations);
            _hotelService.Insert(hotelObj);

            SaveChanges();
            var imageId = 1;

            foreach (var memoryStream in files)
            {
                _manageStorage.UploadImage(path + "\\" + "Hotel-" + hotelObj.HotelId, memoryStream, imageId.ToString());
                imageId++;
            }
            return(hotelDto);
        }