public async Task <IEnumerable <tblPicture> > GetAll(long IdReception, string date) { long idVisit = MYHelper.getIdVisitbyIdReception(IdReception, date); var result = await repository.GetAll(c => c.IdVisit == idVisit); result.ToList().ForEach(c => { c.Filepath = MYHelper.getbase64(Path.Combine(_hostingEnvironment.WebRootPath, "FileUpload", c.Filepath)); }); return(result); }
public async Task <ActionResult <JsonR> > Post([FromForm] tblPicture model) { long idVisit = MYHelper.getIdVisitbyIdReception(model.IdReception, model.date); if (idVisit < 1) { return new JsonR { Title = "error", Message = "چنین ویزیتی وجود ندارد" } } ; model.IdVisit = idVisit; try { string guidefile = string.Empty; if (model.Image.Length > 0) { IFormFile files = model.Image; if (string.IsNullOrEmpty(Path.GetExtension(files.FileName))) { guidefile = Guid.NewGuid() + ".jpg"; } else { guidefile = Guid.NewGuid() + Path.GetExtension(files.FileName); } var filePath = Path.Combine(_hostingEnvironment.WebRootPath, "FileUpload", guidefile); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await files.CopyToAsync(fileStream); fileStream.Flush(); model.Filepath = guidefile; } } await repository.Add(model); return(new JsonR { Title = "success", Message = guidefile }); } catch (Exception err) { return(new JsonR { Title = "error", Message = err.Message }); } }
public async Task <IEnumerable <tblPicture> > GetAll(long IdReception, string date) { long idVisit = MYHelper.getIdVisitbyIdReception(IdReception, date); return(await repository.GetAll(c => c.IdVisit == idVisit)); }