Ejemplo n.º 1
0
        public JsonResponse<string> DeletePhoto(ApprovedImageModel approveModel)
        {
            JsonResponse<string> jsonResponse = new JsonResponse<string>();
            string folderName;
            DirectoryInfo di;
            folderName = Path.Combine("Resources", "Images");
            var pathofImages = Path.Combine(Directory.GetCurrentDirectory(), folderName);
            di = new DirectoryInfo(pathofImages);
            FileInfo[] files = di.GetFiles("*.*", SearchOption.AllDirectories);

            try
            {

                using (IDbConnection dbConnection = new NpgsqlConnection(_ConnectionStringService.Value))
                {
                    dbConnection.Open();

                    using (var transaction = dbConnection.BeginTransaction())
                    {
                       string image_name = dbConnection.Query<string>("select image_name from  candidate_image_logger where id = @p0", new { p0 = approveModel.imageLoggedId }).FirstOrDefault();


                        foreach (FileInfo file in files)
                        {
                            if (file.Name == image_name)
                            {
                                file.Delete();
                                break;
                            }
                        }

                          dbConnection.Query<CandidateImageLogger>("update candidate_image_logger set is_deleted = true where id = @p0", new { p0 = approveModel.imageLoggedId });
                                             
                          transaction.Commit();

                    }
                }
                jsonResponse.IsSuccess = true;
                jsonResponse.Message = "success";
                return jsonResponse;

            }
            catch (Exception e)
            {

                jsonResponse.IsSuccess = false;
                jsonResponse.Message = "fail";
                return jsonResponse;
            }
        }
 public IActionResult DeleteProfilePhoto([FromBody] ApprovedImageModel approveModel)
 {
     return(Ok(_fileUploadService.DeletePhoto(approveModel)));
 }
Ejemplo n.º 3
0
        public JsonResponse<string> updateToApproveProfile(ApprovedImageModel approveModel)
        {
            JsonResponse<string> jsonResponse = new JsonResponse<string>();
            string folderName;
            DirectoryInfo di;

            try
            {

                using (IDbConnection dbConnection = new NpgsqlConnection(_ConnectionStringService.Value))
                {
                    dbConnection.Open();

                    using (var transaction = dbConnection.BeginTransaction())
                    {
                        CandidateImageLogger imageDetails = dbConnection.Query<CandidateImageLogger>("select * from  candidate_image_logger where id = @p0", new { p0 = approveModel.imageLoggedId }).FirstOrDefault();

                        if (imageDetails.is_profile_pic == true)
                        {
                            folderName = Path.Combine("Resources", "Images", "User", imageDetails.user_id.ToString(), "Candidates", imageDetails.candidate_id.ToString(), "Profile Image");

                            var path = Path.Combine(Directory.GetCurrentDirectory(), folderName);

                            if (Directory.Exists(path))
                            {
                                di = new DirectoryInfo(path);

                                foreach (FileInfo fi in di.GetFiles())
                                {
                                    if (fi.Name != imageDetails.image_name)
                                    {
                                        fi.Delete();
                                    }
                                }

                            }

                            dbConnection.Query<CandidateImageLogger>("update candidate_image_logger set is_deleted = true where user_id = @p0 and candidate_id = @p1 and is_approved = true and is_profile_pic = true and is_deleted = false and id != @p2", new { p0 = imageDetails.user_id, @p1 = imageDetails.candidate_id, @p2 = imageDetails.id });

                            dbConnection.Query<CandidateImageLogger>("update candidate_image_logger set is_approved = true , is_profile_pic = true  where id = @p0", new { p0 = approveModel.imageLoggedId });

                        }
                        else if (imageDetails.is_from_other_three_photos == true)
                        {
                            dbConnection.Query<CandidateImageLogger>("update candidate_image_logger set is_approved = true where id = @p0", new { p0 = approveModel.imageLoggedId });

                        }

                        transaction.Commit();

                    }
                }
                jsonResponse.IsSuccess = true;
                jsonResponse.Message = "success";
                return jsonResponse;

            }
            catch (Exception e)
            {

                jsonResponse.IsSuccess = false;
                jsonResponse.Message = "fail";
                return jsonResponse;
            }
        }
 public IActionResult UpdateToApproveProfile([FromBody] ApprovedImageModel approveModel)
 {
     return(Ok(_fileUploadService.updateToApproveProfile(approveModel)));
 }