Ejemplo n.º 1
0
        public IActionResult Post(int year, int month, string title)
        {
            var post = _repo.Post(year, month, title);

            if (post == null)
            {
                throw new Exception("Post not found");
            }

            if (post.Published == false && User.Identity.IsAuthenticated == false)
            {
                throw new Exception("The post is not published");
            }

            var model = Mapper.Map <PostViewModel>(post);

            foreach (var item in model.Images)
            {
                item.ImageUri = _cloudService.GetImageUri(item.ContainerName, item.FileName);
            }

            GetProfileImageUri(model.Comments);

            return(View(model));
        }
Ejemplo n.º 2
0
        public IActionResult Get(int year, int month, string title)
        {
            try
            {
                var post = _repo.Post(year, month, title);

                if (post == null)
                {
                    return(Json(new PostViewModel()));
                }

                var model = Mapper.Map <PostViewModel>(post);

                foreach (var item in model.Images)
                {
                    item.ImageUri = _cloudService.GetImageUri(item.ContainerName, item.FileName);
                }

                return(Json(model));
            }
            catch (Exception ex)
            {
                _logger.LogError("Failed to get post", ex);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { Message = ex.Message }));
            }
        }
Ejemplo n.º 3
0
        public PortfolioViewModel(ICloudStorageService cloudService, IBlogRepository repo)
        {
            Projects = Mapper.Map <ICollection <ProjectViewModel> >(repo.GetAllProjects());

            foreach (var proj in Projects)
            {
                proj.Image.ImageUri = cloudService.GetImageUri(proj.Image?.ContainerName, proj.Image?.FileName);
            }
        }
Ejemplo n.º 4
0
        public AboutMeViewModel(ICloudStorageService cloudService, IBlogRepository repo)
        {
            Events = Mapper.Map <ICollection <TimelineEventViewModel> >(repo.GetTimelineEvents("aboutMe").Result);

            foreach (var ev in Events)
            {
                ev.Image.ImageUri = cloudService.GetImageUri(ev.Image.ContainerName, ev.Image.FileName);
            }
        }
Ejemplo n.º 5
0
        public GalleryViewModel(ICloudStorageService cloudService, IBlogRepository repo, string containerName)
        {
            Images = Mapper.Map <ICollection <ImageDescriptionViewModel> >(repo.GetAllImages(containerName).Result);

            foreach (var img in Images)
            {
                img.ImageUri = cloudService.GetImageUri(img.ContainerName, img.FileName);
            }
        }
Ejemplo n.º 6
0
 private void GetImageUris(ICollection <PostViewModel> posts, ICloudStorageService cloudService)
 {
     foreach (var post in posts)
     {
         foreach (var img in post.Images)
         {
             img.ImageUri = cloudService.GetImageUri(img.ContainerName, img.FileName);
         }
     }
 }
Ejemplo n.º 7
0
 private void GetImageUri(ImageDescriptionViewModel model)
 {
     model.ImageUri = _cloudService.GetImageUri(model.ContainerName, model.FileName);
 }