Exemple #1
0
        public bool Edit(string roadId, string roadName, string startingPoint, string endPoint, double roadLength,
                         string description, string video, IFormFile imageFromForm, int viewRating, int surfaceRating,
                         int pleasureRating)
        {
            if (roadName == null || startingPoint == null || endPoint == null || roadLength == 0.00 ||
                description == null)
            {
                return(false);
            }

            string embedYoutubeUrl = null;

            if (video != null)
            {
                embedYoutubeUrl = videoService.ReturnEmbedYoutubeLink(video);
            }

            var road = this.context.Roads.FirstOrDefault(x => x.Id == roadId);

            if (road == null)
            {
                return(false);
            }

            road.RoadName       = roadName;
            road.Description    = description;
            road.StartingPoint  = startingPoint;
            road.EndPoint       = endPoint;
            road.RoadLength     = roadLength;
            road.SurfaceRating  = surfaceRating;
            road.ViewRating     = viewRating;
            road.PleasureRating = pleasureRating;

            if (road.Video != video)
            {
                road.Video = embedYoutubeUrl;
            }

            context.SaveChanges();

            if (imageFromForm != null)
            {
                road.CoverPhoto = null;

                var image = imageService.AddPhoto(imageFromForm);

                image.Name = roadName + "main";

                var coverPhoto = new CoverPhotoRoad {
                    Image = image, ImageId = image.Id, Road = road, RoadId = road.Id
                };

                context.CoverPhotoRoads.Add(coverPhoto);
                context.SaveChanges();

                road.CoverPhoto   = coverPhoto;
                road.CoverPhotoId = coverPhoto.Id;

                context.SaveChanges();
            }

            return(true);
        }
Exemple #2
0
        public bool Create(string roadName, string startingPoint, string endPoint, double roadLength,
                           string description, string video, string userId, IFormFile imageFromForm, ICollection <IFormFile> photos,
                           int viewRating, int surfaceRating, int pleasureRating)
        {
            if (roadName == null || startingPoint == null || endPoint == null || roadLength == 0.00 ||
                description == null || userId == null || imageFromForm == null)
            {
                return(false);
            }

            if (this.context.Roads.Any(x => x.RoadName == roadName))
            {
                return(false);
            }

            string embedYoutubeUrl = null;

            if (video != null)
            {
                embedYoutubeUrl = videoService.ReturnEmbedYoutubeLink(video);
            }

            var imageList = new List <Image>();

            foreach (var photo in photos)
            {
                imageList.Add(this.imageService.AddPhoto(photo));
            }

            Road road = new Road
            {
                RoadName       = roadName,
                Description    = description,
                EndPoint       = endPoint,
                PostedOn       = DateTime.UtcNow,
                StartingPoint  = startingPoint,
                RoadLength     = roadLength,
                Video          = embedYoutubeUrl,
                UserId         = userId,
                Photos         = imageList,
                SurfaceRating  = surfaceRating,
                ViewRating     = viewRating,
                PleasureRating = pleasureRating
            };

            context.Roads.Add(road);
            context.SaveChanges();

            var image = imageService.AddPhoto(imageFromForm);

            image.Name = roadName + "main";

            var coverPhoto = new CoverPhotoRoad {
                Image = image, ImageId = image.Id, Road = road, RoadId = road.Id
            };

            context.CoverPhotoRoads.Add(coverPhoto);
            context.SaveChanges();

            road.CoverPhoto   = coverPhoto;
            road.CoverPhotoId = coverPhoto.Id;

            context.SaveChanges();
            return(true);
        }