public ActionResult Detail(string id)
        {
            ViewBag.PlacesPicklist = this.GetPlacesPicklist();

            if (id == null)
            {
                return(RedirectToAction("Index", "Place"));
            }

            string token = Session["token"].ToString();

            var client = connector.Initial();

            client.Timeout = -1;
            var request = new RestRequest("admin/tour-infos/" + id, Method.GET);

            request.AddHeader("Authorization", "Bearer " + token);
            IRestResponse response = client.Execute(request);

            TourInfoModel         tourInfo = new TourInfoModel();
            TourInfoEditViewModel model;

            if (response.IsSuccessful)
            {
                var settings = new JsonSerializerSettings
                {
                    NullValueHandling     = NullValueHandling.Ignore,
                    MissingMemberHandling = MissingMemberHandling.Ignore
                };
                TourInfoApiResultModel content = JsonConvert.DeserializeObject <TourInfoApiResultModel>(response.Content, settings);
                tourInfo = content.Data[0];
                model    = new TourInfoEditViewModel()
                {
                    Id             = tourInfo.Id,
                    Name           = tourInfo.Name,
                    Images         = tourInfo.Images,
                    Rating         = tourInfo.Rating,
                    StartPlace     = tourInfo.StartPlace.Id,
                    DestinatePlace = tourInfo.DestinatePlace.Id,
                    CreateBy       = tourInfo.CreateBy.Name
                };
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Index", "Place"));
            }
        }
Esempio n. 2
0
        public JsonResult GetTourInfo(int Id)
        {
            Tour tour = db.Tours.Find(Id);

            string TourTitle = "";

            if (tour.FromId == tour.DestinationId)
            {
                TourTitle = tour.City.CityName + " Tour";
            }
            else
            {
                TourTitle = tour.City.CityName + " - " + tour.City1.CityName + " Tour";
            }

            List <TourImage> timg          = tour.TourImages.ToList();
            List <string>    TourImagesUrl = new List <string>();

            foreach (TourImage img in timg)
            {
                TourImagesUrl.Add(img.ImageURL);
            }

            UserModel Guide = new UserModel
            {
                Id           = tour.User.Id,
                Fullname     = tour.User.Fullname,
                Email        = tour.User.Email,
                Phone        = tour.User.Phone,
                ProfileImage = tour.User.ProfileImage,
                Rating       = tour.User.OverallRating
            };

            List <Feedback>      feedbacks     = tour.Feedbacks.OrderByDescending(f => f.Id).Take(5).ToList();
            List <FeedbackModel> feedbacksList = new List <FeedbackModel>();

            foreach (Feedback fdbck in feedbacks)
            {
                string        date     = fdbck.Date.ToString("HH:mm dd MMM yyyy");
                FeedbackModel feedback = new FeedbackModel
                {
                    Id               = fdbck.Id,
                    Text             = fdbck.Text,
                    Rating           = fdbck.Rating,
                    Date             = date,
                    UserId           = fdbck.UserId,
                    UserFullname     = fdbck.User.Fullname,
                    UserProfileImage = fdbck.User.ProfileImage
                };
                feedbacksList.Add(feedback);
            }

            string Price = tour.Price.ToString("#,##");

            TourInfoModel TourInfo = new TourInfoModel
            {
                Id              = tour.Id,
                FromCity        = tour.City.CityName,
                DestCity        = tour.City1.CityName,
                TourTitle       = TourTitle,
                TourImagesUrl   = TourImagesUrl,
                Guide           = Guide,
                FeedbacksList   = feedbacksList,
                Desc            = tour.Description,
                Categories      = tour.Category,
                Duration        = tour.Duration,
                DurationType    = tour.DurationType.Type,
                Price           = Price,
                Currency        = tour.Currency.CurrencyName,
                Vehicle         = tour.Vehicle,
                Accomodation    = tour.Accomodation?.AccomodationName,
                AccomodationLvl = tour.AccomodationLevel?.Level
            };

            return(Json(TourInfo, JsonRequestBehavior.AllowGet));
        }