public async Task SyncReports(IEnumerable <PrinterBIReportMaster> reports) { var oldReports = await _context.PrinterBIReportMaster.ToListAsync(); _context.PrinterBIReportMaster.RemoveRange(oldReports); await _context.SaveChangesAsync(); await _context.PrinterBIReportMaster.AddRangeAsync(reports); await _context.SaveChangesAsync(); }
public async Task <string> SaveAssignToAllReports(IEnumerable <Guid> reports) { List <AssignedReportsToAll> reportlist = new List <AssignedReportsToAll>(); List <Guid> correctReportIdlist = new List <Guid>(); List <Guid> wrongReportIdlist = new List <Guid>(); var allreports = await _context.PrinterBIReportMaster.ToListAsync(); foreach (Guid id in reports) { if (allreports.Any(x => x.Id == id)) { correctReportIdlist.Add(id); } else { wrongReportIdlist.Add(id); } } if (wrongReportIdlist.Count > 0) { return(string.Join(',', wrongReportIdlist)); } else { var oldReports = await _context.AssignedReportsToAll.ToListAsync(); _context.AssignedReportsToAll.RemoveRange(oldReports); await _context.SaveChangesAsync(); foreach (Guid reportId in reports) { reportlist.Add(new AssignedReportsToAll { ReportId = reportId }); } await _context.AssignedReportsToAll.AddRangeAsync(reportlist); await _context.SaveChangesAsync(); return(string.Empty); } }
public async Task <string> SaveAssignReportsToUser(int userId, List <Guid> reports) { List <Guid> correctReportIdlist = new List <Guid>(); List <Guid> wrongReportIdlist = new List <Guid>(); List <Guid> blockedReports = new List <Guid>(); var allReports = await _context.PrinterBIReportMaster.ToListAsync(); foreach (Guid id in reports) { if (allReports.Any(x => x.Id == id)) { correctReportIdlist.Add(id); } else { wrongReportIdlist.Add(id); } } if (wrongReportIdlist.Count > 0) { return(string.Join(',', wrongReportIdlist)); } else { var oldUserReports = await _context.AssignedReportsToUser.Where(x => x.UserId == userId).ToListAsync(); _context.AssignedReportsToUser.RemoveRange(oldUserReports); await _context.SaveChangesAsync(); var oldBlockedReports = await _context.BlockedReportsForUser.Where(x => x.UserId == userId).ToListAsync(); _context.BlockedReportsForUser.RemoveRange(oldBlockedReports); await _context.SaveChangesAsync(); var assignedToall = await _context.AssignedReportsToAll.ToListAsync(); foreach (var assignObj in assignedToall) { if (reports.Any(e => e == assignObj.ReportId)) { reports.Remove(assignObj.ReportId); } else { blockedReports.Add(assignObj.ReportId); } } List <BlockedReportsForUser> blockedlist = new List <BlockedReportsForUser>(); foreach (var obj in blockedReports) { blockedlist.Add(new BlockedReportsForUser { ReportId = obj, UserId = userId }); } List <AssignedReportsToUser> userreportlist = new List <AssignedReportsToUser>(); foreach (var obj in reports) { if (allReports.Any(x => x.Id == obj)) { userreportlist.Add(new AssignedReportsToUser { ReportId = obj, UserId = userId }); } } await _context.BlockedReportsForUser.AddRangeAsync(blockedlist); await _context.AssignedReportsToUser.AddRangeAsync(userreportlist); await _context.SaveChangesAsync(); return(string.Empty); } }