Esempio n. 1
0
 public static NewsFileCreateDto ToDto(this NewsFileCreateViewModel source, string fileName, long length)
 {
     return new NewsFileCreateDto
     {
         FileName = fileName,
         FileType = source.FileType,
         Length = length,
         NewsId = source.NewsId,
         Title = source.Title
     };
 }
Esempio n. 2
0
        public IActionResult File(NewsFileCreateViewModel 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, "NewsFile", maxLength);

                if (uploadResult.IsSuccess)
                {
                    var serviceResult = _adminService.CreateNewsFile(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.NewsId }));
        }