Ejemplo n.º 1
0
        /// <summary>
        /// 根据酒店图片id获取酒店图片
        /// </summary>
        /// <param name="hotelId"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public HotelImage GetHotelImageByKey(Guid hotelId, Guid id)
        {
            JXHotelDbContext dbContext  = this.EFContext.dbContext as JXHotelDbContext;
            HotelImage       hotelImage = dbContext.Hotels.Find(hotelId).HotelImages.Where(image => image.Id.Equals(id)).FirstOrDefault();

            return(hotelImage);
        }
Ejemplo n.º 2
0
        public void AddImage(Guid hotelId, List <string> imageNames)
        {
            var hotel = Get(hotelId);

            if (hotel == null)
            {
                return;
            }

            hotel.HotelImages = new List <HotelImage>();

            foreach (var imageName in imageNames)
            {
                var image = _unitOfWork.GetRepository <Image>().FirstOrDefault(i => i.Name == imageName);

                if (image != null)
                {
                    var hotelImage = new HotelImage
                    {
                        ImageId = image.Id,
                        HotelId = hotel.Id
                    };

                    hotel.HotelImages.Add(hotelImage);
                }
            }

            _hotelRepository.Update(hotel);
            _unitOfWork.Commit();
        }
Ejemplo n.º 3
0
        public HotelImageEditViewModel Update(HotelImageEditViewModel HotelImage)
        {
            HotelImage _HotelImage = HotelImageRepo.Update(HotelImage.toModel());

            unitOfWork.commit();
            return(_HotelImage.toEditViewModel());
        }
Ejemplo n.º 4
0
        // PUT api/HotelImageUpload/5
        public IHttpActionResult PutHotelImage(int id, HotelImage hotelimage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != hotelimage.ImageID)
            {
                return(BadRequest());
            }

            db.Entry(hotelimage).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HotelImageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult Image(FormCollection fc, HttpPostedFileBase file)
        {
            int   id = Convert.ToInt32(Request.Form["rid"]);
            Hotel r  = db.Hotels.Find(id);

            ViewBag.rname = r.Name;
            ViewBag.rid   = r.Id;

            ViewBag.ImgList = db.HotelImages.Where(x => x.HotelId == r.Id).ToList();



            HotelImage hotel = new HotelImage();

            int    count = 2;
            string pt    = Path.GetFileNameWithoutExtension(file.FileName);
            string ex    = Path.GetExtension(file.FileName);
            string xx    = pt + ex;

            //  string FleName = pt + "." + ex;
            // var z = db.tblImgs.Where(x => x.imgUrl == pt + "%**%"+ ex).ToList();

            //Check If file exist or not
            if (System.IO.File.Exists(@"E:\KarnalTravel\KarnalTravel\Uploading\" + pt + ex))
            {
                int  ii = 2;
                bool x  = true;
                while (x)
                {
                    string fn = pt + "(" + ii + ")";
                    if (System.IO.File.Exists(@"E:\KarnalTravel\KarnalTravel\Uploading\" + fn + ex))
                    {
                        ii++;
                    }
                    else
                    {
                        x              = false;
                        pt             = fn;
                        count          = ii;
                        hotel.ImageUrl = fn + ex;
                    }
                }
                string pathRename = Path.Combine("~/Uploading/" + pt + ex);
                hotel.ImageUrl = pt + ex;
                file.SaveAs(Server.MapPath(pathRename));
            }
            else
            {
                file.SaveAs(@"E:\KarnalTravel\KarnalTravel\Uploading\" + pt + ex);
                hotel.ImageUrl = pt + ex;
            }
            //-------------

            hotel.HotelId = Convert.ToInt32(Request.Form["rid"]);

            db.HotelImages.Add(hotel);
            db.SaveChanges();
            return(RedirectToAction("Image", new { id = hotel.HotelId }));
        }
Ejemplo n.º 6
0
 public static HotelImageEditViewModel toEditViewModel(this HotelImage model)
 {
     return(new HotelImageEditViewModel()
     {
         ID = model.ID,
         Image = model.Image
     });
 }
Ejemplo n.º 7
0
        public IHttpActionResult GetHotelImage(int id)
        {
            HotelImage hotelimage = db.HotelImages.Find(id);

            if (hotelimage == null)
            {
                return(NotFound());
            }

            return(Ok(hotelimage));
        }
Ejemplo n.º 8
0
        public IHttpActionResult DeleteHotelImage(int id)
        {
            HotelImage hotelimage = db.HotelImages.Find(id);

            if (hotelimage == null)
            {
                return(NotFound());
            }


            db.HotelImages.Remove(hotelimage);
            db.SaveChanges();

            return(Ok(hotelimage));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Validates and saves all of the uploaded images to the database.
        /// </summary>
        /// <param name="images"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task UploadImagesAsync(List <IFormFile> images, int id)
        {
            var theMain = true;

            foreach (IFormFile image in images)
            {
                IFormFile a = image;
                var       formFileContent =
                    await FileHelper.ProcessFormFile <HotelViewModel>(
                        image, ModelState, _permittedExtensions,
                        _fileSizeLimit);

                var file = new HotelImage()
                {
                    Content       = formFileContent,
                    UntrustedName = image.FileName,
                    HotelId       = id,
                    IsMain        = theMain
                };
                await _portalService.CreateHotelImage(file);

                theMain = false;
            }
        }
Ejemplo n.º 10
0
        private Hotel processOneHotel(XmlNode hotelNode)
        {
            try
            {
                Hotel result = new Hotel();
                result.HotelInfo = new HotelInformation();
                result.HotelInfo.Address = new Address();

                foreach (XmlNode node in hotelNode.ChildNodes)
                {

                    if (node.Name == "id") {
                        result.HotelInfo.Id = long.Parse(node.ChildNodes.Item(0).InnerText);
                    }

                    if (node.Name == "name") {
                        result.HotelInfo.Name = node.InnerText;

                        //Console.WriteLine("  Hotel Id: " + result.HotelInfo.Id + ", Name: " + result.HotelInfo.Name);
                    }

                    if (node.Name == "addr")
                    {
                        foreach (XmlNode item in node.ChildNodes)
                        {
                            if (item.Name == "line1"){
                                result.HotelInfo.Address.Street1 = item.InnerText;
                            }
                            if (item.Name == "line2"){
                                result.HotelInfo.Address.Street2 = item.InnerText;
                            }

                            if (item.Name == "city"){
                                result.HotelInfo.Address.City = new City { Name = item.InnerText };
                            }

                            if (item.Name == "state"){
                                result.HotelInfo.Address.State = new State { Code = item.Attributes.Item(0).InnerText, Name = item.Attributes.Item(1).InnerText };
                            }

                            if (item.Name == "country"){
                                result.HotelInfo.Address.Country = new Country { Code = item.Attributes.Item(0).InnerText, Name = item.Attributes.Item(1).InnerText };
                            }

                            if (item.Name == "postal"){
                                result.HotelInfo.Address.Postcode = item.InnerText;
                            }
                        }
                        //Console.WriteLine("  Address is processed");
                    }

                    if (node.Name == "latitude"){
                        result.HotelInfo.Address.Latitude = float.Parse(node.InnerText);
                    }
                    if (node.Name == "longitude"){
                        result.HotelInfo.Address.Longtitude = float.Parse(node.InnerText);
                    }

                    if (node.Name == "stars"){
                        result.HotelInfo.StarRating = float.Parse(node.InnerText);
                    }

                    if (node.Name == "airportsDesc"){
                        result.HotelInfo.AreaInfo = "Airport Description: " + node.InnerText;
                    }

                    if (node.Name == "description"){
                        result.HotelInfo.HotelDescription = node.InnerText;
                    }

                    if (node.Name == "checkInTime")
                    {
                        if (result.HotelInfo.PolicyInfo == null) { result.HotelInfo.PolicyInfo = new HotelPolicy(); }
                        result.HotelInfo.PolicyInfo.CheckInTime = node.InnerText;
                    }
                    if (node.Name == "checkOutTime"){
                        if (result.HotelInfo.PolicyInfo == null) { result.HotelInfo.PolicyInfo = new HotelPolicy(); }
                        result.HotelInfo.PolicyInfo.CheckOutTime = node.InnerText;
                    }

                    if (node.Name == "amenities")
                    {
                        result.HotelInfo.Amenities = new List<Amenity>();
                        foreach (XmlNode amenityNode in node.ChildNodes)
                        {
                            if (amenityNode.FirstChild.Name == "code")
                            {
                                Amenity amenity = new Amenity();
                                amenity.Code = amenityNode.FirstChild.InnerText;
                                if (amenitiesList.getAmenitiesCodeList.Contains(amenity.Code))
                                {
                                    amenity.Name = amenitiesList.getAmenitiesCodeList[amenity.Code].ToString();
                                    result.HotelInfo.Amenities.Add(amenity);
                                }
                                else
                                {
                                    //Console.WriteLine("  *** Amenity code NOT found: '" + amenity.Code + "'   ***");
                                }
                            }

                        }

                        //Console.WriteLine("  Amenities are processed");
                    }

                    if (node.Name == "medias")
                    {
                        result.HotelInfo.Images = new List<HotelImage>();
                        foreach (XmlNode mediaNode in node.ChildNodes)
                        {
                            HotelImage image = new HotelImage();
                            for (int i = 0; i <= mediaNode.ChildNodes.Count - 1; i++)
                            {
                                if (mediaNode.ChildNodes[i].Name == "type"){
                                    image.Code = mediaNode.ChildNodes[i].InnerText;
                                }

                                if (mediaNode.ChildNodes[i].Name == "url"){
                                    image.URL = mediaNode.ChildNodes[i].InnerText;
                                }
                            }
                            result.HotelInfo.Images.Add(image);
                        }

                        //Console.WriteLine("  Medias are processed");
                    }

                    if (node.Name == "facilities")
                    {
                        result.HotelInfo.Facilities = new List<Facility>();
                        foreach (XmlNode facilityNode in node.ChildNodes)
                        {
                            Facility facility = new Facility();
                            for (int i = 0; i <= facilityNode.ChildNodes.Count - 1; i++)
                            {
                                if (facilityNode.ChildNodes[i].Name == "type")
                                {
                                    facility.Code = facilityNode.ChildNodes[i].InnerText;
                                }

                                if (facilityNode.ChildNodes[i].Name == "desc")
                                {
                                    facility.Description = facilityNode.ChildNodes[i].InnerText;
                                }
                            }
                            result.HotelInfo.Facilities.Add(facility);
                        }

                        //Console.WriteLine("  Facilities are processed");
                    }

                    if (node.Name == "userReviews")
                    {
                        result.HotelInfo.GuestReview = new GuestReview();
                        foreach (XmlNode reviewNode in node.ChildNodes)
                        {
                            if (reviewNode.Name == "userScore")
                            {
                                result.HotelInfo.GuestReview.UserScore = float.Parse(reviewNode.InnerText);
                            }
                            if (reviewNode.Name == "numberOfReviews")
                            {
                                result.HotelInfo.GuestReview.NumberOfReviews = long.Parse(reviewNode.InnerText);
                            }
                            if (reviewNode.Name == "numberOfRecommendations")
                            {
                                result.HotelInfo.GuestReview.NumberOfRecommendations = long.Parse(reviewNode.InnerText);
                            }
                        }

                        //Console.WriteLine("  UserReviews is processed");
                    }

                    if (node.Name == "chainCode"){
                        result.HotelInfo.Chain = new Identification { Code = node.InnerText };
                    }

                }

                return result;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return null;
            }
        }
Ejemplo n.º 11
0
        public HotelImageViewModel GetByID(int id)
        {
            HotelImage HotelImage = HotelImageRepo.GetByID(id);

            return(HotelImage.toViewModel());
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 根据酒店图片id获取酒店图片
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public HotelImageDataObject GetHotelImageByKey(Guid hotelId, Guid id)
        {
            HotelImage hotelImage = hotelRepository.GetHotelImageByKey(hotelId, id);

            return(AutoMapper.Mapper.Map <HotelImage, HotelImageDataObject>(hotelImage));
        }
Ejemplo n.º 13
0
 public void UpdateImage(string hotelId, string supplierFamily, HotelImage sourceImage)
 {
     throw new NotImplementedException();
 }