Ejemplo n.º 1
0
        //----------------------------------------------------------------------------------

        public ActionResult InformPlace(int id)
        {
            ViewBag.Page   = pageInfo.setView("InformPlace").setTitle("InformPlace");
            ViewBag.Method = HttpContext.Request.HttpMethod;

            PlaceDTO placeDTO = PlaceService.Get(id);

            if (placeDTO == null)
            {
                return(HttpNotFound());
            }
            List <PlacePhotoDTO> photo  = PlacePhotoServices.GetAll().Where(x => x.PlaceId == id).ToList();
            List <ReviewDTO>     review = ReviewServices.GetAll().Where(x => x.PlaceId == id).OrderByDescending(x => x.Date).ToList();

            //IQueryable<Rating> R = db.Ratings.Where(x => x.IdPlace == id);

            int RLike   = review.Count(x => x.ValueLike == 1);
            int RDis    = review.Count(x => x.ValueLike == 2);
            int RCheck  = review.Count(x => x.Checkin == 1);
            int RRating = (RLike + RDis == 0) ? 0 : Convert.ToInt32(Math.Round(10.0 * Convert.ToDouble(RLike) / Convert.ToDouble(RLike + RDis)));

            List <UserDTO> userDTO = UserServices.GetAll();


            PlaceDTO obj = new PlaceDTO()
            {
                Id          = placeDTO.Id,
                Name        = placeDTO.Name,
                Longitude   = placeDTO.Longitude,
                Latitude    = placeDTO.Latitude,
                Address     = placeDTO.Address,
                Description = placeDTO.Description,
                Phone       = placeDTO.Phone,

                Site        = placeDTO.Site,
                WorkingHour = placeDTO.WorkingHour
            };

            ViewBag.Album    = photo;
            ViewBag.Checkins = RCheck;
            ViewBag.Comments = review;
            ViewBag.Dislike  = RDis;
            ViewBag.Like     = RLike;
            ViewBag.Ratings  = RRating;
            ViewBag.Login    = userDTO;
            return(View(obj));
        }
Ejemplo n.º 2
0
        public ActionResult AddPlace(HttpPostedFileBase[] Photo)
        {
            string Name        = Request.Form["Name"];
            string Address     = Request.Form["Address"];
            string Site        = Request.Form["Site"];
            string Phone       = Request.Form["Phone"];
            string Description = Request.Form["Description"];
            string Coordinates = Request.Form["Coordinates"];
            var    re          = new Regex(@"[\[\]]");

            double[] NewCoordinates = re.Replace(Coordinates, "").Split(',')
                                      .Select(x => Convert.ToDouble(x.Replace(".", ","))).ToArray();
            string   Tags       = Request.Form["Tags"];
            DateTime DateCreate = DateTime.Now;


            if (Name != "" && Address != "" && NewCoordinates.Length == 2 && Identity.isAuthentication)
            {
                PlaceDTO placeDTO = new PlaceDTO();
                placeDTO.Address     = Address;
                placeDTO.Creater     = Identity.user.Id;
                placeDTO.Longitude   = NewCoordinates[0];
                placeDTO.Latitude    = NewCoordinates[1];
                placeDTO.DateCreate  = DateCreate;
                placeDTO.Description = Description;
                placeDTO.Name        = Name;
                placeDTO.Tags        = Tags;;
                placeDTO.Site        = Site;
                placeDTO.Phone       = Phone;
                PlaceService.Create(placeDTO);
                PlaceDTO      newPlace = PlaceService.GetAll().FirstOrDefault(x => x.Name == Name && x.Creater == Identity.user.Id && x.DateCreate == DateCreate);
                PlacePhotoDTO placePhoto;
                string        dir = Server.MapPath("~/Resources/Images/Places/" + newPlace.Id);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                if (Photo.Count() > 0)
                {
                    foreach (HttpPostedFileBase photo in Photo)
                    {
                        string type = photo.FileName.Split('.').Last();

                        string[] dirs = Directory.GetFiles(Server.MapPath("~/Resources/Images/Places/" + newPlace.Id), "*");
                        string   src  = "/Resources/Images/Places/" + newPlace.Id + "/" + cryptMD5.GetHash(dirs.Length.ToString()) + "." + type;
                        string   path = Server.MapPath("~" + src);

                        photo.SaveAs(path);

                        placePhoto         = new PlacePhotoDTO();
                        placePhoto.Main    = false;
                        placePhoto.SRC     = src;
                        placePhoto.PlaceId = newPlace.Id;
                        PlacePhotoServices.Create(placePhoto);
                    }
                    placePhoto = PlacePhotoServices.GetAll().FirstOrDefault(x => x.Main == false && x.PlaceId == newPlace.Id);
                    if (placePhoto != null)
                    {
                        placePhoto.Main = true;
                        PlacePhotoServices.Update(placePhoto);
                    }
                }
            }
            return(RedirectToAction("Place"));
        }