internal static TEReportDto GetReport(TEReport report) { return new TEReportDto { ID = report.ID, Name = report.Name, SsrsServerUrl = report.SsrsServerUrl, Path = report.Path, Roles = report.ReportAssignments==null?null: string.Join(",", report.ReportAssignments.Select(p => p.Role.Name).OrderBy(p => p)), RoleIds = report.ReportAssignments == null ? null : report.ReportAssignments.Select(p => p.RoleID), CategoryIds = report.CategoryAssignments == null ? null : report.CategoryAssignments.Select(p => p.CategoryID), Categories = report.CategoryAssignments == null ? null : string.Join(",", report.CategoryAssignments.Select(p => p.Category.Name).OrderBy(p => p)), }; }
internal static void SaveReport(ViewModels.ReportEditVM report) { int id = report.ID; var reportUpdate = new TEReport { ID=report.ID, Name = report.Name, SsrsServerUrl = report.SsrsServerUrl, Path = report.Path }; if (id == 0) { Db.TEReports.Add(reportUpdate); Db.SaveChanges(); id = reportUpdate.ID; } else { reportUpdate = Db.TEReports.FirstOrDefault(p => p.ID == id); reportUpdate.Name = report.Name; reportUpdate.SsrsServerUrl = report.SsrsServerUrl; reportUpdate.Path = report.Path; foreach (var assignment in Db.ReportAssignments.Where(p=>p.TEReportID == id)) { reportUpdate.ReportAssignments.Remove(assignment); Db.ReportAssignments.Remove(assignment); } foreach (var categoryassignment in Db.CategoryAssignments.Where(p => p.TEReportID == id)) { reportUpdate.CategoryAssignments.Remove(categoryassignment); Db.CategoryAssignments.Remove(categoryassignment); } Db.TEReports.AddOrUpdate(reportUpdate); Db.SaveChanges(); } if (report.SelectedRoles != null) { foreach (var roleid in report.SelectedRoles) { Db.ReportAssignments.Add(new ReportAssignment { TEReportID = id, RoleID = roleid }); } } if (report.SelectedCategories != null) { foreach (var categoryid in report.SelectedCategories) { Db.CategoryAssignments.Add(new CategoryAssignment { TEReportID = id, CategoryID = categoryid }); } } Db.SaveChanges(); }