public CommentsResponse GetCommentsByChart(int smartChartId) { var response = new CommentsResponse(); try { var commentRepository = new ChartCommentRepository(); var userRepository = new UserProfileRepository(); var comments = commentRepository.Query().Where(x => x.IdSmartChart == smartChartId && x.IsActive == true).OrderBy(x => x.DatePosted).Take(25).ToList(); foreach (var comment in comments) { int userId = Convert.ToInt32(comment.IdUser); response.Comments.Add(new ChartCommentDto() { Message = comment.Message, DatePosted = comment.DatePosted, UserName = userRepository.Query().FirstOrDefault(x => x.UserId == userId).UserName, IdComment = comment.IdComment, IdUser = userId.ToString() }); } // CHECK ROLE - IsAppAdmin commentRepository.Dispose(); response.Acknowledgment = true; response.Message = "Success"; } catch (Exception ex) { _logger.Error("Error Getting the comments for chartid: " + smartChartId + ". With the exception: " + ex.Message); response.Acknowledgment = false; response.Message = "Error: " + ex.Message; } return(response); }
//private static readonly Logger _log = LogManager.GetCurrentClassLogger(); public SmartChartResponse GetChartsBySmartReportId(int smartReportId) { var response = new SmartChartResponse(); try { var smartChartRepository = new SmartChartRepository(); var smartReportRepository = new SmartReportRepository(); var chartCommentsRepository = new ChartCommentRepository(); var smartReport = smartReportRepository.Query().FirstOrDefault(x => x.idSmartReport == smartReportId); if (smartReport != null) { response.Delivery = new ServiceDeliveryDto() { DateDelivered = smartReport.ServiceDelivery.DateDelivered, DeliveryDateTo = smartReport.ServiceDelivery.DeliveryDateTo }; response.SmartReport = new SmartReportDto() { ReportName = smartReport.ReportName, Insights = smartReport.Insights }; var smartCharts = smartChartRepository.Query() .Where(x => x.idSmartReport == smartReportId && x.ChartType.idChartType != 10) .OrderBy(x => x.ChartOrder) .ToList(); foreach (var smartChart in smartCharts) { response.SmartCharts.Add(new SmartChartDto() { idSmartChart = smartChart.idSmartChart, IdChartType = smartChart.IdChartType, ChartType = null, Insights = smartChart.Insights, CssClasses = smartChart.CssClasses, ChartName = smartChart.ChartName, ChartTypeName = smartChart.ChartType.ChartTypeName, ChartOrder = smartChart.ChartOrder, CommentsCount = chartCommentsRepository.Query().Where(x => x.IdSmartChart == smartChart.idSmartChart && x.IsActive == true).Count() }); } smartChartRepository.Dispose(); smartReportRepository.Dispose(); response.Acknowledgment = true; response.Message = "Success"; } } catch (Exception ex) { response.Acknowledgment = false; response.Message = "Error getting SmartCharts. Exception :" + ex.Message; } return(response); }
public CommentsResponse AddChartComment(ChartCommentDto comment) { var response = new CommentsResponse(); try { var commentRepository = new ChartCommentRepository(); var userRepository = new UserProfileRepository(); var newComment = new ChartComment { IdUser = comment.IdUser, DatePosted = DateTime.Now, Message = comment.Message, IdSmartChart = comment.IdSmartChart, IsActive = true }; commentRepository.Add(newComment); commentRepository.SaveChanges(); int userId = Convert.ToInt32(comment.IdUser); response.Comments.Add(new ChartCommentDto() { Message = newComment.Message, DatePosted = newComment.DatePosted, UserName = userRepository.Query().FirstOrDefault(x => x.UserId == userId).UserName, IdComment = newComment.IdComment, IdUser = userId.ToString() }); commentRepository.Dispose(); response.Acknowledgment = true; response.Message = "Success"; } catch (Exception ex) { _logger.Error("Error adding comment. With the exception: " + ex.Message); response.Acknowledgment = false; response.Message = "Error: " + ex.Message; } return(response); }
public CommentsResponse DeactivateCommentsByChartId(int userId, int idComment, string[] appRoles) { var response = new CommentsResponse(); var isAppAdmin = new List <string>(appRoles).Exists(x => x == "Administrator"); try { var commentRepository = new ChartCommentRepository(); var userRepository = new UserProfileRepository(); var userXSubscription = new UsersXSubscriptionRepository(); var comment = commentRepository.Query().FirstOrDefault(x => x.IdComment == idComment); var isSubAdmin = userXSubscription.Query().Any(x => x.IdSubscriptionRoleTypes == 1 && x.idSubscription == comment.SmartChart.SmartReport.ServiceDelivery.ServiceSubscription.idServiceSubscription && x.idUser == userId); if (comment.IdUser == userId.ToString() || isAppAdmin || isSubAdmin) { comment.IsActive = false; commentRepository.SaveChanges(); commentRepository.Dispose(); response.Acknowledgment = true; response.Message = "Success"; } else { _logger.Error("User " + userId + " does not have the right roles to delete this comment " + idComment + " date:" + DateTime.Now.ToString()); response.Acknowledgment = false; response.Message = "User " + userId + " does not have the right roles to delete this comment " + idComment + " date:" + DateTime.Now.ToString(); } } catch (Exception ex) { _logger.Error("Error Getting the comment " + idComment + ". With the exception: " + ex.Message); response.Acknowledgment = false; response.Message = "Error: " + ex.Message; } return(response); }