public IHttpActionResult Get([FromUri] ReqGetGalleryModel Model) { int Count = -1; if (ModelState.IsValid) { if (string.IsNullOrEmpty(Model.Category)) { return(NotFound()); } string IdPatient = Model.Token.Split('/')[0]; string Folder = $"{AppSettings["FolderImages"]}\\{IdPatient}\\{Model.Category}"; if (Exists(Folder)) { Count = GetFiles(Folder).Length; } } return(Ok(new { TotalImages = Count })); }
public IHttpActionResult Get([FromUri] ReqGetGalleryModel Model) { var Result = new Dictionary <string, List <string> >(); if (ModelState.IsValid) { try { string IdPatient = Model.Token.Split('/')[0]; string FolderImages = $"{AppSettings["FolderImages"]}\\{IdPatient}\\"; List <string> Categories = new List <string> { "vacunas", "medicamentos", "recetas", "generales", "laboratorio", "diagnosticos" }; if (!string.IsNullOrEmpty(Model.Category)) { Categories = new List <string> { Model.Category.ToLower() }; } foreach (string Category in Categories) { string Folder = $"{FolderImages}{Category}"; if (Exists(Folder)) { List <string> Images = new List <string>(); string[] Files; if (Model.LastImages.HasValue && Model.LastImages.Value > 0) { Files = (string[])GetFiles(Folder).OrderByDescending(x => new FileInfo(x).CreationTime).Take(Model.LastImages.Value); } else { Files = GetFiles(Folder).OrderByDescending(x => new FileInfo(x).CreationTime).ToArray(); } foreach (string Img in Files) { if (!((File.GetAttributes(Img) & FileAttributes.Hidden) == FileAttributes.Hidden)) { string FileName = Path.GetFileName(Img); string Url = $"{AppSettings["UrlEmeci"]}{IdPatient}/{Category}/{FileName}"; Images.Add(Url); } } Result.Add(Category, Images); } else { Result.Add(Category, new List <string>()); } } } catch { } } if (Result.Count > 0) { return(Ok(new { Success = true, Images = Result })); } else { return(NotFound()); } }