Example #1
0
        public IActionResult Edit(Guid id)
        {
            PostRepositorio postRepositorio = new PostRepositorio(this.configuration.GetConnectionString("default"));
            PostAplicacao   postAplicacao   = new PostAplicacao(postRepositorio);

            var postDto = postAplicacao.Procurar(id);

            var post = PostMapping.toModel(postDto);

            CategoriaRepositorio categoriaRepositorio = new CategoriaRepositorio(this.configuration.GetConnectionString("default"));
            CategoriaAplicacao   categoriaAplicacao   = new CategoriaAplicacao(categoriaRepositorio);

            var categoriaDtos = categoriaAplicacao.Listar();

            List <Categoria> categorias = new List <Categoria>();

            foreach (var categoria in categoriaDtos)
            {
                categorias.Add(CategoriaMapping.toModel(categoria));
            }

            ViewData["title"] = "Edição Post";

            ViewData["post"]       = post;
            ViewData["categorias"] = categorias;

            return(View());
        }
Example #2
0
        private void createTypeMappingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var tempNode = (ElasticNode)treeViewAdv1.SelectedNode.Tag;

            if (tempNode != null)
            {
                PostMapping analyzeTest = new PostMapping(currentElasticSearchInstance, tempNode.IndexName, string.Empty);
                analyzeTest.ShowDialog();
            }
        }
Example #3
0
        public IActionResult Insert(Post post)
        {
            PostRepositorio postRepositorio = new PostRepositorio(this.configuration.GetConnectionString("default"));
            PostAplicacao   postAplicacao   = new PostAplicacao(postRepositorio);

            PostDto postDto = PostMapping.toDto(post);

            postAplicacao.Insert(postDto);

            return(RedirectToAction("Index"));
        }
Example #4
0
        public PostMapping getSiglePost(int postId)
        {
            Post        p        = postRepository.FindById(postId);
            PostMapping pMapping = new PostMapping();

            pMapping.Id           = p.Id;
            pMapping.Body         = p.Body;
            pMapping.CreateDate   = p.CreateDate.GetValueOrDefault();
            pMapping.EmbedCode    = p.EmbedCode;
            pMapping.UserId       = p.UserId;
            pMapping.username     = p.User == null ? "Không xác định sở hữu" : p.User.Username;
            pMapping.userProfile  = p.User == null || p.User.ProfileImage == null || p.User.ProfileImage.Equals("") ? "/Content/Images/defaultProfile.png" : p.User.ProfileImage;
            pMapping.userFullName = p.User == null ? "Không xác định" : p.User.Fullname;
            pMapping.houseName    = p.User.House == null ? "Không xác định" : p.User.House.HouseName;
            return(pMapping);
        }
Example #5
0
        public ActionResult Detail(int postId)
        {
            //Convert to post Mapping
            Post          p      = postService.findPostById(postId);
            List <string> imgUrl = new List <string>();

            PostMapping pMapping   = new PostMapping();
            int         imageCount = 0;

            if (p != null)
            {
                pMapping.Id     = p.Id;
                pMapping.Status = p.Status;
                pMapping.Body   = p.Body != null?p.Body.Replace("\n", "<br/>") : "";

                pMapping.CreateDate   = p.CreateDate.GetValueOrDefault();
                pMapping.EmbedCode    = p.EmbedCode;
                pMapping.UserId       = p.UserId;
                pMapping.username     = p.User == null ? "Không xác định sở hữu" : p.User.Username;
                pMapping.userProfile  = p.User == null || p.User.ProfileImage == null || p.User.ProfileImage.Equals("") ? "/Content/Images/defaultProfile.png" : p.User.ProfileImage;
                pMapping.userFullName = p.User == null ? "Không xác định" : p.User.Fullname;
                pMapping.houseName    = p.User.House == null ? "Không xác định" : p.User.House.HouseName;
                pMapping.houseId      = p.User.HouseId == null ? 0 : p.User.HouseId.Value;

                List <Image> listImages = imageService.GetImagesByPostId(p.Id);
                imageCount = listImages.Count;
                //                if (listImages.Count == 1)
                //                {
                //                    frameImageHeight = 476;
                //                    System.Drawing.Image img = System.Drawing.Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + listImages[0].thumbnailUrl);
                //                    imageCount = img.Height;
                //                }
                //                else if (listImages.Count > 1)
                //                {
                //                    frameImageHeight = ((int)listImages.Count / 2) * 237;
                //                }
            }
            else
            {
                ViewBag.ErrorMsg = "Rất tiếc! Bài viết này đã không còn tồn tại trong hệ thống.";
                return(View("ErrorMsg"));
            }
            ViewBag.Post        = pMapping;
            ViewBag.ImageCount  = imageCount;
            ViewBag.CurrentUser = userService.findById(int.Parse(User.Identity.GetUserId()));
            return(View("ViewSinglePost"));
        }
Example #6
0
        public Object getSinglePost(int postId)
        {
            PostMapping singlePost = postService.getSiglePost(postId);

            // Serializer settings
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.ContractResolver           = new CustomResolver(typeof(PostMapping));
            settings.PreserveReferencesHandling = PreserveReferencesHandling.None;
            settings.ReferenceLoopHandling      = ReferenceLoopHandling.Ignore;
            settings.Formatting = Formatting.Indented;

            // Do the serialization and output to the console
            string json = JsonConvert.SerializeObject(singlePost, settings);

            return(json);
        }
Example #7
0
        public IActionResult Post(Guid id)
        {
            PostRepositorio postRepositorio = new PostRepositorio(this.configuration.GetConnectionString("default"));
            PostAplicacao   postAplicacao   = new PostAplicacao(postRepositorio);

            var postDto = postAplicacao.Procurar(id);

            var post = PostMapping.toModel(postDto);

            ViewData["title"]   = post.titulo;
            ViewBag.titulo      = post.titulo;
            ViewBag.subtitulo   = post.resumo;
            ViewBag.imagemFundo = "post-bg.jpg";

            ViewData["post"] = post;

            return(View());
        }
Example #8
0
        public IActionResult Index()
        {
            PostRepositorio postRepositorio = new PostRepositorio(this.configuration.GetConnectionString("default"));
            PostAplicacao   postAplicacao   = new PostAplicacao(postRepositorio);

            var postDtos = postAplicacao.Listar();

            List <Post> posts = new List <Post>();

            foreach (var post in postDtos)
            {
                posts.Add(PostMapping.toModel(post));
            }

            ViewData["title"] = "Posts";

            ViewData["posts"] = posts;

            return(View());
        }
Example #9
0
        public ActionResult GetPostDetail(int postId)
        {
            //Convert to post Mapping
            Post p = postService.findPostById(postId);
            MessageViewModels     response  = new MessageViewModels();
            PostMapping           pMapping  = new PostMapping();
            List <PostImageModel> listImage = new List <PostImageModel>();

            if (p != null)
            {
                pMapping.Id   = p.Id;
                pMapping.Body = p.Body != null?p.Body.Replace("\n", "<br/>") : "";

                pMapping.CreateDate   = p.CreateDate.GetValueOrDefault();
                pMapping.EmbedCode    = p.EmbedCode;
                pMapping.UserId       = p.UserId;
                pMapping.username     = p.User == null ? "Không xác định sở hữu" : p.User.Username;
                pMapping.userProfile  = p.User == null || p.User.ProfileImage == null || p.User.ProfileImage.Equals("") ? "/Content/Images/defaultProfile.png" : p.User.ProfileImage;
                pMapping.userFullName = p.User == null ? "Không xác định" : p.User.Fullname;
                pMapping.houseName    = p.User.House == null ? "Không xác định" : p.User.House.HouseName;
                pMapping.houseId      = p.User.HouseId == null ? 0 : p.User.HouseId.Value;
                List <Image>   listImages = imageService.GetImagesByPostId(p.Id);
                PostImageModel imgModel   = null;
                foreach (var img in listImages)
                {
                    imgModel              = new PostImageModel();
                    imgModel.id           = img.id;
                    imgModel.postId       = img.postId.Value;
                    imgModel.thumbnailurl = img.thumbnailUrl;
                    imgModel.userCropUrl  = img.userCropUrl;
                    imgModel.url          = img.url;
                    listImage.Add(imgModel);
                }
                pMapping.ListImages = listImage;
                response.Data       = pMapping;
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Example #10
0
        public IActionResult Index()
        {
            ViewData["title"]   = "Home";
            ViewBag.titulo      = "Blog .NET Core";
            ViewBag.subtitulo   = "Home";
            ViewBag.imagemFundo = "home-bg.jpg";

            PostRepositorio postRepositorio = new PostRepositorio(this.configuration.GetConnectionString("default"));
            PostAplicacao   postAplicacao   = new PostAplicacao(postRepositorio);

            var postDtos = postAplicacao.Listar();

            List <Post> posts = new List <Post>();

            foreach (var post in postDtos)
            {
                posts.Add(PostMapping.toModel(post));
            }

            ViewData["posts"] = posts;

            return(View());
        }
Example #11
0
 public static void Register(IMapperConfigurationExpression config)
 {
     CommentsMapping.Register(config);
     PostMapping.Register(config);
 }
Example #12
0
        public ActionResult Update(PostMapping post)
        {
            //Convert to post Mapping
            Post p = postService.findPostById(post.Id);
            MessageViewModels response = new MessageViewModels();

            if (p != null)
            {
                p.Body       = post.Body;
                p.UpdateDate = DateTime.Now;
                if (!post.EmbedCode.IsNullOrWhiteSpace())
                {
                    p.EmbedCode = post.EmbedCode;
                }
                else
                {
                    p.EmbedCode = null;
                }

                if (null != post.ListImgRemoved)
                {
                    foreach (var imgId in post.ListImgRemoved)
                    {
                        imageService.RemoveById(imgId);
                    }
                }

                if (null != post.ListImages)
                {
                    var listObjImages = post.ListImages;
                    foreach (var imgObj in listObjImages)
                    {
                        if (imgObj.id == 0)
                        {
                            Image eImg = new Image();
                            eImg.thumbnailUrl = imgObj.thumbnailurl;
                            eImg.userCropUrl  = imgObj.thumbnailurl;
                            eImg.url          = imgObj.url;
                            eImg.createdDate  = DateTime.Now;
                            eImg.postId       = p.Id;
                            eImg.originalUrl  = imgObj.originUrl;
                            imageService.saveImage(eImg);
                        }
                        else
                        {
                            Image eImg = imageService.FindById(imgObj.id);
                            if (eImg != null && !eImg.thumbnailUrl.Equals(imgObj.userCropUrl))
                            {
                                eImg.thumbnailUrl = eImg.userCropUrl;
                                imageService.Update(eImg);
                            }
                        }
                    }

                    List <Image> postImage = imageService.GetImagesByPostId(p.Id).ToList();

                    bool isUpdateImage = false;
                    if (postImage.Count == 1)
                    {
                        System.Drawing.Image img = System.Drawing.Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + postImage[0].originalUrl);
                        postImage[0].thumbnailUrl = new StringBuilder(AmsConstants.ImageFilePathDownload).Append(AroundProviderController.SaveImage(img, AppDomain.CurrentDomain.BaseDirectory + AmsConstants.ImageFilePathDownload, 504, 394, 0, false)).ToString();;
                        imageService.Update(postImage[0]);
                    }
                    else if (postImage.Count == 2)
                    {
                        System.Drawing.Image img  = System.Drawing.Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + postImage[0].originalUrl);
                        System.Drawing.Image img2 = System.Drawing.Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + postImage[1].originalUrl);
                        if (img.Height > img.Width && img2.Height > img2.Width) // Check 2 image is portrail
                        {
                            postImage[0].thumbnailUrl = new StringBuilder(AmsConstants.ImageFilePathDownload).Append(AroundProviderController.SaveImage(img, AppDomain.CurrentDomain.BaseDirectory + AmsConstants.ImageFilePathDownload, 394, 394, 0, false)).ToString();;
                            postImage[1].thumbnailUrl = new StringBuilder(AmsConstants.ImageFilePathDownload).Append(AroundProviderController.SaveImage(img2, AppDomain.CurrentDomain.BaseDirectory + AmsConstants.ImageFilePathDownload, 394, 394, 0, false)).ToString();;
                            imageService.Update(postImage[0]);
                            imageService.Update(postImage[1]);
                        }
                        else if (img.Width > img.Height && img2.Width > img2.Height)// Check 2 image is landscape
                        {
                            postImage[0].thumbnailUrl = new StringBuilder(AmsConstants.ImageFilePathDownload).Append(AroundProviderController.SaveImage(img, AppDomain.CurrentDomain.BaseDirectory + AmsConstants.ImageFilePathDownload, 504, 504, 0, false)).ToString();;
                            postImage[1].thumbnailUrl = new StringBuilder(AmsConstants.ImageFilePathDownload).Append(AroundProviderController.SaveImage(img2, AppDomain.CurrentDomain.BaseDirectory + AmsConstants.ImageFilePathDownload, 504, 504, 0, false)).ToString();;
                            imageService.Update(postImage[0]);
                            imageService.Update(postImage[1]);
                        }
                        else
                        {
                            foreach (var image in postImage)
                            {
                                image.thumbnailUrl = image.userCropUrl;
                                imageService.Update(image);
                            }
                        }
                    }
                    else if (postImage.Count == 3)
                    {
                        string curElemment = "";

                        /*Process thumbnail image*/
                        int index = -1;
                        for (int i = 0; i < postImage.Count; i++)
                        {
                            curElemment = postImage[i].originalUrl;
                            System.Drawing.Image img = System.Drawing.Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + curElemment);
                            if (img.Width > img.Height)
                            {
                                string imageSavePath = AppDomain.CurrentDomain.BaseDirectory + AmsConstants.ImageFilePathDownload;

                                postImage[i].thumbnailUrl = new StringBuilder(AmsConstants.ImageFilePathDownload).Append(AroundProviderController.SaveImage(img, imageSavePath, 504, 394, 0, false)).ToString();;

                                var tempItem = postImage[i].thumbnailUrl;
                                postImage[i].thumbnailUrl = postImage[0].thumbnailUrl;
                                postImage[0].thumbnailUrl = tempItem;

                                tempItem = postImage[i].originalUrl;
                                postImage[i].originalUrl = postImage[0].originalUrl;
                                postImage[0].originalUrl = tempItem;

                                tempItem = postImage[i].userCropUrl;
                                postImage[i].userCropUrl = postImage[0].userCropUrl;
                                postImage[0].userCropUrl = tempItem;

                                tempItem         = postImage[i].url;
                                postImage[i].url = postImage[0].url;
                                postImage[0].url = tempItem;

                                imageService.Update(postImage[0]);
                                index = 0;
                                break;
                            }
                        }
                        Image image = null;
                        for (int i = 0; i < postImage.Count; i++)
                        {
                            image = postImage[i];
                            if (i != index)
                            {
                                image.thumbnailUrl = image.userCropUrl;
                                imageService.Update(image);
                            }
                        }
                    }
                }
                postService.UpdatePost(p);
                PostMapping newData = new PostMapping();
                newData.Id        = p.Id;
                newData.Body      = p.Body;
                newData.EmbedCode = p.EmbedCode;
                List <Image> listImages = imageService.GetImagesByPostId(p.Id);
                newData.ImageCount = listImages.Count;
                response.Data      = newData;
            }
            else
            {
                response.StatusCode = -1;
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Example #13
0
        public List <PostMapping> getAllPostMapping(int?tokenId, int?houseId)
        {
            List <Post> allPostWithHouseID = new List <Post>();
            List <Post> allRaw             = getAllPost();
            List <Post> result             = new List <Post>();



            if (houseId != null)
            {
                foreach (Post p in allRaw)
                {
                    if (p.User.HouseId == houseId)
                    {
                        allPostWithHouseID.Add(p);
                    }
                }
            }
            else
            {
                allPostWithHouseID = allRaw;
            }
            allPostWithHouseID.OrderByDescending(p => p.CreateDate);

            int position;

            if (tokenId == null)
            {
                position = -1;
            }
            else
            {
                var lastTokenPost = postRepository.FindById(tokenId);
                position = allPostWithHouseID.FindIndex(p => p.Id == tokenId);

                if (allPostWithHouseID.Count > 0 && (lastTokenPost != null && lastTokenPost.Status != null && lastTokenPost.Status == SLIM_CONFIG.POST_STATUS_HIDE))
                {
                    var listPostNewer = allPostWithHouseID.Where(p => p.CreateDate < lastTokenPost.CreateDate).ToList();
                    if (listPostNewer.Count() != 0)
                    {
                        tokenId  = listPostNewer.First().Id;
                        position = allPostWithHouseID.FindIndex(p => p.Id == tokenId) - 1;
                    }
                }
            }
            Post managerFirstPost = allPostWithHouseID.Where(p => p.User.RoleId == SLIM_CONFIG.USER_ROLE_MANAGER).FirstOrDefault();

            for (int i = position + 1; i < allPostWithHouseID.Count && result.Count < SLIM_CONFIG.POST_NUMBER_SOCIAL_FEED; i++)
            {
                if (tokenId != -1 && allPostWithHouseID.ElementAt(i) == managerFirstPost)
                {
                    continue;
                }
                result.Add(allPostWithHouseID.ElementAt(i));
            }
            //Add manager's post to head
            if (tokenId == -1)
            {
                if (managerFirstPost != null)
                {
                    if (result.Contains(managerFirstPost))
                    {
                        result.Remove(managerFirstPost);
                    }
                    result.Insert(0, managerFirstPost);
                }
            }
            //Convert to post Mapping
            List <PostMapping> postMappingResult = new List <PostMapping>();

            foreach (Post p in result)
            {
                PostMapping pMapping = new PostMapping();
                pMapping.Id           = p.Id;
                pMapping.Body         = p.Body;
                pMapping.CreateDate   = p.CreateDate.GetValueOrDefault();
                pMapping.EmbedCode    = p.EmbedCode;
                pMapping.UserId       = p.UserId;
                pMapping.username     = p.User == null ? "Không xác định sở hữu" : p.User.Username;
                pMapping.userProfile  = p.User == null || p.User.ProfileImage == null || p.User.ProfileImage.Equals("") ? "/Content/Images/defaultProfile.png" : p.User.ProfileImage;
                pMapping.userFullName = p.User == null ? "Không xác định" : p.User.Fullname;
                pMapping.houseName    = p.User.House == null ? "Không xác định" : p.User.House.HouseName;
                pMapping.houseId      = p.User.HouseId == null ? 0 : p.User.HouseId.Value;
                postMappingResult.Add(pMapping);
            }
            //Convert to post Mapping

            return(postMappingResult);
        }
Example #14
0
        public static void RunWith(HttpListenerContext context)
        {
            string path       = context.Request.Url.PathAndQuery;
            string httpMethod = context.Request.HttpMethod;

            try
            {
                HttpMethod method = (HttpMethod)Enum.Parse(typeof(HttpMethod), httpMethod, true);
                switch (method)
                {
                case HttpMethod.GET:
                    GetResponse(GetMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.POST:
                    GetResponse(PostMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.DELETE:
                    GetResponse(DeleteMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.PUT:
                    GetResponse(PutMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.PATCH:
                    GetResponse(PatchMapping.FindPath(path, method, context), context);
                    break;

                case HttpMethod.OPTIONS:
                    var requestedMethod  = Enum.Parse <HttpMethod>(context.Request.Headers.Get("Access-Control-Request-Method"));
                    var requestedHeaders = context.Request.Headers.Get("Access-Control-Request-Headers");
                    var response         = AbstractMapping.HandleOptionsRequest(path, requestedMethod, requestedHeaders);
                    SendResponse(response, context);
                    break;

                default:
                    throw new ServerRequestMethodNotSupportedException($"{httpMethod} is not supported", context);
                }
            }
            catch (ServerRequestMethodNotSupportedException ex)
            {
                ExceptionHandler.HandleException(ex, context);
            }
            catch (ServerEndpointNotValidException ex)
            {
                ExceptionHandler.HandleException(ex, context);
            }
            catch (Exception ex)
            {
                try
                {
                    throw new InternalServerErrorException(ex.Message, context, ex);
                }
                catch (InternalServerErrorException e)
                {
                    ExceptionHandler.HandleException(e, context);
                }
            }
        }