private async void ArchiveOlderInstructions(IEnumerable <Instruction> instructions) { foreach (var newInstruction in instructions) { var oldInstructions = (await _instructionDataService.Where(i => i.DeviceId == newInstruction.DeviceId && i.InstructedId == newInstruction.InstructedId && i.CreatedAt < newInstruction.CreatedAt && i.Id != newInstruction.Id)).ToArray(); _instructionPdfService.ArchiveOlderInstructions( oldInstructions.Where(o => o.Path != newInstruction.Path)); foreach (var oldInstruction in oldInstructions) { oldInstruction.IsArchived = true; await _instructionDataService.Update(oldInstruction.Id, oldInstruction); } } }
public async Task Execute() { var instructions = await _instructionDataService.Where(i => string.IsNullOrEmpty(i.OldInstructedString)); var users = (await _userDataService.GetAll()).ToList(); foreach (var instruction in instructions) { var instructionInfo = new FileInfo(instruction.Path); var instructedName = instructionInfo.Name.Split("_")[0]; if (!Helper.IsValidEmail(instructedName)) { continue; } var user = users.FirstOrDefault(u => u.Email == instructedName); if (user is null) { user = new User { Email = instructedName }; users.Add(user); var mailSplit = instructedName.Split("@")[0].Split("."); if (mailSplit.Length != 2) { continue; } user.FirstName = mailSplit[0]; user.LastName = mailSplit[1]; } instruction.Instructed = user; await _instructionDataService.Update(instruction.Id, instruction); } }