Example #1
0
        public bool Add(CategoryDTO categoryDTO)
        {
            categoryDTO.CategoryId = hashService.GenerateId();

            CategoryEntity categoryEntity  = dataMapper.MapCategoryDTOToEntity(categoryDTO);
            bool           addSuccessfully = categoryRepository.Add(categoryEntity);

            return(addSuccessfully);
        }
Example #2
0
        public bool Add(CommentDTO commentDTO)
        {
            commentDTO.CommentId   = hashService.GenerateId();
            commentDTO.CreatedDate = DateTime.Now;
            commentDTO.Username    = "******";

            CommentEntity commentEntity   = dataMapper.MapCommentDTOToEntity(commentDTO);
            bool          addSuccessfully = commentRepository.Add(commentEntity);

            return(addSuccessfully);
        }
Example #3
0
        public bool Add(PostDTO postDTO)
        {
            postDTO.PostId      = hashService.GenerateId();
            postDTO.CreatedDate = DateTime.Now;
            postDTO.UpdatedDate = DateTime.Now;

            PostEntity postEntity = dataMapper.MapPostDTOToEntity(postDTO);

            postEntity.CategoryId = postEntity.PostCategory.CategoryId;

            bool addSuccessfully = postRepository.Add(postEntity);

            return(addSuccessfully);
        }
Example #4
0
        public async Task <IHttpActionResult> UploadImages()
        {
            object jsonObject;

            try
            {
                HttpContext httpContext     = HttpContext.Current;
                string      imageServerRoot = httpContext.Server.MapPath(APISettings.IMAGE_ROOT);
                MultipartFormDataStreamProvider streamProvider = new MultipartFormDataStreamProvider(imageServerRoot);
                List <APIImageModel>            imageModels    = new List <APIImageModel>();
                await Request.Content.ReadAsMultipartAsync(streamProvider);

                foreach (MultipartFileData file in streamProvider.FileData)
                {
                    FileInfo fileInfo       = new FileInfo(file.Headers.ContentDisposition.FileName.Trim('"'));
                    string   imageExtension = fileInfo.Extension;
                    string   imageId        = hashService.GenerateId();
                    string   imageName      = imageId + imageExtension;
                    string   newImagePath   = Path.Combine(imageServerRoot, imageName);

                    bool moveSuccessfully = imageService.MoveImage(oldImagePath: file.LocalFileName, newImagePath);

                    if (moveSuccessfully)
                    {
                        APIImageModel imageModel = new APIImageModel()
                        {
                            ImageId   = imageId,
                            Extension = imageExtension
                        };

                        imageModels.Add(imageModel);
                    }
                }

                jsonObject = new {
                    status = 200,
                    data   = imageModels
                };
            }
            catch (Exception)
            {
                jsonObject = new { status = 500 };
            }

            return(Json(jsonObject));
        }