public UploadedFull UploadFile(IFormFile file) { Logger.LogWarning("Begin upload file"); FileLogic fileLogic = new FileLogic(); UploadedFull uploaded = fileLogic.UploadFile(file); return(uploaded); }
public Task <Media> CreateMediaAsync(IFormFile file) { try { Media media = new Media(); List <Media> medias = new List <Media>(); if (file != null) { UploadedFull uploadedRs = this.UploadFile(file); Logger.LogWarning("Begin create media"); if (uploadedRs != null) { media.Name = uploadedRs.Uploaded.FileName; media.SubName = uploadedRs.Uploaded.FileName; media.Path = uploadedRs.Uploaded.UrlPath; media.Size = uploadedRs.Uploaded.Length; media.Type = uploadedRs.Uploaded.ContentType; media.ResizeType = "original"; } medias.Add(media); if (uploadedRs.ResizeUploaded.Count() > 0) { foreach (Uploaded media1 in uploadedRs.ResizeUploaded) { medias.Add(new Media { Name = media1.FileName, SubName = media1.FileName, Path = media1.UrlPath, Size = media1.Length, Type = media1.ContentType, ResizeType = media1.ResizeType }); } } //await _uow.GetRepository<Media>().AddAsync(media); _uow.GetRepository <Media>().AddRange(medias); _uow.SaveChanges(); return(Task.FromResult(media)); } return(Task.FromResult(media)); } catch (Exception ex) { Logger.LogError(ex.Message.ToString()); throw ex; } }