public JsonResponse<List<CandidateImagaeModel>> GetUploadedPhotos(UserCandidateIDModel IDModel) { List<CandidateImageLogger> candidateImages = new List<CandidateImageLogger>(); JsonResponse<List<CandidateImagaeModel>> jsonResponse = new JsonResponse<List<CandidateImagaeModel>>(); jsonResponse.Data = new List<CandidateImagaeModel>(); FileInfo[] filesForApproval = new FileInfo[100]; DirectoryInfo di; var folderName = Path.Combine("Resources", "Images"); var pathofImages = Path.Combine(Directory.GetCurrentDirectory(), folderName); if (!Directory.Exists(pathofImages)) { di = Directory.CreateDirectory(pathofImages); } di = new DirectoryInfo(pathofImages); FileInfo[] files = di.GetFiles("*.*", SearchOption.AllDirectories); CandidateImagaeModel imagemodel; int i = 0; try { using (IDbConnection dbConnection = new NpgsqlConnection(_ConnectionStringService.Value)) { if (files.Length > 0) { dbConnection.Open(); using (var transaction = dbConnection.BeginTransaction()) { candidateImages = dbConnection.Query<CandidateImageLogger>("SELECT * FROM candidate_image_logger where is_from_other_three_photos = true and is_deleted = false and user_id = @p0 and candidate_id = @p1 ", new { p0 = IDModel.user_id, p1 = IDModel.candidate_id }).ToList(); List<CandidateImageLogger> profiles = dbConnection.Query<CandidateImageLogger>("SELECT * FROM candidate_image_logger where is_profile_pic = true and is_deleted = false and user_id = @p0 and candidate_id = @p1 ", new { p0 = IDModel.user_id, p1 = IDModel.candidate_id }).ToList(); if (profiles != null) { foreach (CandidateImageLogger profile in profiles) { if (profiles.Count == 1) { candidateImages.Add(profile); break; } else { if (profile.is_approved == false) { candidateImages.Add(profile); break; } } } } foreach (CandidateImageLogger image in candidateImages) { foreach (FileInfo file in files) { if (file.Name == image.image_name) { using (FileStream fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read)) { byte[] ImageData = File.ReadAllBytes(file.FullName); string base64String = Convert.ToBase64String(ImageData, 0, ImageData.Length); imagemodel = new CandidateImagaeModel(); imagemodel.is_profile = image.is_profile_pic; imagemodel.is_from_other_three_photos = image.is_from_other_three_photos; imagemodel.imageLoggedid = image.id; imagemodel.user = dbConnection.Query<User>("Select * from user_table where id = @id", new { id = image.user_id }).FirstOrDefault(); imagemodel.candidate = dbConnection.Query<Candidate>("Select * from candidate where id = @id", new { id = image.candidate_id }).FirstOrDefault(); imagemodel.image = "data:image/jpeg;base64," + base64String; jsonResponse.Data.Add(imagemodel); break; } } } } transaction.Commit(); } } } jsonResponse.IsSuccess = true; jsonResponse.Message = "success"; return jsonResponse; } catch (Exception e) { jsonResponse.IsSuccess = false; jsonResponse.Message = "fail"; return jsonResponse; } }
public IActionResult GetUplodedPhotos([FromBody] UserCandidateIDModel iDModel) { return(Ok(_fileUploadService.GetUploadedPhotos(iDModel))); }