public CandidateComment SaveComment(CandidateComment candidateComment) { var exitComments = context.Comments.Where(a => a.CandidateId == candidateComment.Id); context.Comments.RemoveRange(exitComments); context.SaveChanges(); var interViewComment = candidateComment.InterviewComments; var comments = new List <Comment>(); // HR comment var hrComment = interViewComment.HRComment; if (!string.IsNullOrWhiteSpace(hrComment)) { comments.Add(new Comment() { CandidateId = candidateComment.Id, RoleId = GetIdByName(nameof(Role), ConstStrings.HR), Text = hrComment }); } // Interviewer comment var interviewerComments = interViewComment.InterviewerComments; if (GenericMethod.IsStringOrIntPropertiesHasValue(interviewerComments)) { comments.Add(new Comment() { CandidateId = candidateComment.Id, RoleId = GetIdByName(nameof(Role), ConstStrings.Interviewer), Text = JsonSerializer.Serialize(interviewerComments) }); } // PM comment var pmComment = interViewComment.PMComment; if (!string.IsNullOrWhiteSpace(pmComment)) { comments.Add(new Comment() { CandidateId = candidateComment.Id, RoleId = GetIdByName(nameof(Role), ConstStrings.PM), Text = pmComment }); } // Client comment var clientComment = interViewComment.ClientComment; if (!string.IsNullOrWhiteSpace(clientComment)) { comments.Add(new Comment() { CandidateId = candidateComment.Id, RoleId = GetIdByName(nameof(Role), ConstStrings.Client), Text = clientComment }); } context.Comments.AddRange(comments); context.SaveChanges(); return(candidateComment); }