public async Task <AnnounceMathDocs> UploadFileAsync(AnnounceMathDocs announce, string initialPath, EntityContextWEB context) { string path = Path.Combine(initialPath, announce.File.FileName); //<--- Create Directory if it is not exists. if (!Directory.Exists(initialPath)) { Directory.CreateDirectory(initialPath); } //<--- Delete current file if the new file have same name as current file. if (File.Exists(path)) { File.Delete(path); } //<--- Save file. using (FileStream stream = new FileStream(path, FileMode.Create)) { await announce.File.CopyToAsync(stream); } //<--- Insert Data. await InsertAsync(announce, context); return(announce); }
public async Task InsertAsync(AnnounceMathDocs model, EntityContextWEB context) { var isexists = await model.IsExistsDocsNameAsync(model.File.FileName, context); if (isexists) { await context.AnnounceDocs .Where(t => t.DocsName == model.DocsName) .UpdateAsync(t => new AnnounceMathDocs { LastModifyDate = DateTime.Now, LastModifyBy = Current.UserID }); } else { context.AnnounceDocs.Add(model); await context.SaveChangesAsync(); } }