private List <ProjectMetricModel> GetProjectMetrics(ICollection <ProjectMetric> metrics, bool metricProps = false, bool dashboard = false) => metrics.Select(m => { ProjectMetricModel projectMetric = _projectMetricService.ConvertToModel(m); if (metricProps) { projectMetric.Metric = _metricService.ConvertToModel(m.Metric); if (dashboard) { projectMetric.Metric.Columns = _metricService.GetMetricColumns(m.Metric.MetricColumn); projectMetric.Metric.MetricType = _metricTypeService.ConvertToModel(m.Metric.MetricType); } } return(projectMetric); }).ToList();
private async Task <bool> CheckMetric(ProjectMetricModel projectMetric, BaseResponseModel response) { Metric metric = await Database.Metric.FirstOrDefaultAsync(a => a.Id == projectMetric.MetricId && (a.Public || (a.CompanyId.HasValue && a.CompanyId == CurrentUser.CompanyId))); if (metric != null) { if (projectMetric.Warning && metric.MetricType.NumberMetric) { projectMetric.Warning = false; } return(true); } else { response.Success = false; response.Message = "Unknown metric!"; return(false); } }
public async Task <BaseResponseModelPost> Create(ProjectMetricModel request) { BaseResponseModelPost response = new BaseResponseModelPost(); if (request.Validate()) { if (await CheckMetric(request, response) && await CheckProject(request.ProjectId, response) && TestURL(request.DataUrl, response)) { ProjectMetric projectMetric = new ProjectMetric { MetricId = request.MetricId, ProjectId = request.ProjectId, CreateDate = DateTime.Now, LastUpdateDate = DateTime.Now, DataUrl = request.DataUrl, DataUsername = request.DataUsername, DataPassword = PasswordHelper.Base64Encode(request.DataPassword), Warning = request.Warning, MinimalWarningValue = request.Warning ? request.MinimalWarningValue ?? 0 : default(decimal?) }; await Database.ProjectMetric.AddAsync(projectMetric); await Database.SaveChangesAsync(); response.Id = projectMetric.Id; response.Message = "Project metric was successfully created!"; } } else { response.Success = false; response.Message = "Some of the required properties is not present!"; } return(response); }
public async Task <BaseResponseModel> Edit(ProjectMetricModel request) { BaseResponseModel response = new BaseResponseModel(); if (request.Validate()) { if (await CheckMetric(request, response) && await CheckProject(request.ProjectId, response) && TestURL(request.DataUrl, response)) { ProjectMetric projectMetric = await Load(request.Id, response); if (projectMetric != null) { projectMetric.DataUrl = request.DataUrl; projectMetric.DataUsername = request.DataUsername; projectMetric.Warning = request.Warning; projectMetric.MinimalWarningValue = request.Warning ? request.MinimalWarningValue ?? 0 : default(decimal?); if (!string.IsNullOrEmpty(request.DataPassword)) { projectMetric.DataPassword = PasswordHelper.Base64Encode(request.DataPassword); } await Database.SaveChangesAsync(); response.Message = "Project metric was successfully edited!"; } } } else { response.Success = false; response.Message = "Some of the required properties is not present!"; } return(response); }