Example #1
0
 public static PostFileCreateDto ToDto(this PostFileCreateViewModel source, string fileName, long length)
 {
     return(new PostFileCreateDto
     {
         FileName = fileName,
         FileType = source.FileType,
         Length = length,
         PostId = source.PostId,
         Title = source.Title
     });
 }
Example #2
0
        public IActionResult File(PostFileCreateViewModel model)
        {
            if (model.File == null)
            {
                Swal(false, "فایلی انتخاب نکرده اید");
            }
            else
            {
                long?maxLength = 0;

                if (model.FileType == Domain.Enumeration.FileType.Image)
                {
                    maxLength = 500 * 1024;
                }
                else
                {
                    maxLength = 25 * 1024 * 1024;
                }

                var uploadResult = _fileService.Upload(model.File, "PostFile", maxLength);

                if (uploadResult.IsSuccess)
                {
                    var serviceResult = _adminService.CreatePostFile(model.ToDto(uploadResult.Data, model.File.Length));
                    if (serviceResult.IsSuccess)
                    {
                        Swal(true, "عملیات با موفقیت صورت گرفت");
                    }
                    else
                    {
                        Swal(false, serviceResult.Errors.FirstOrDefault());
                    }
                }
                else
                {
                    Swal(false, uploadResult.Errors.FirstOrDefault());
                }
            }
            return(RedirectToAction(nameof(File), new { id = model.PostId }));
        }