public async Task <PlanDocs> UploadFileAsync(FileUpload model, string initialPath) { PlanDocs planDocs = new PlanDocs { PlanCode = null, DocsName = model.File.FileName, AddBy = null, LastModifyBy = null }; string path = Path.Combine(initialPath, model.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 model.File.CopyToAsync(stream); } return(planDocs); }
public async Task <List <PlanDocs> > GetDocByIDAsync(PlanDocs model, EntityContextWEB context) { if (model.PlanCode == "All") { return(await context.PlanDocs.ToListAsync()); } else { return(await context.PlanDocs .Where(c => c.PlanCode == model.PlanCode) .Select(c => new PlanDocs { ID = c.ID }) .ToListAsync()); } }