public async Task <bool> AddAsync(VerifiedDisasterReport document) { try { Console.WriteLine(document); document.CreatedAt = DateTime.Now.ToString(); document.LastUpdatedAt = ""; document.IsActive = true; await _context.VerifiedDisasterReportCollection.InsertOneAsync(document); return(true); } catch (Exception ex) { Console.WriteLine(ex); throw ex; } }
public async void ResourceAllocationAsync(VerifiedDisasterMessage request) { var copier = new ClassValueCopier(); VerifiedDisasterReport newReport = copier.ConvertAndCopy <VerifiedDisasterReport, VerifiedDisasterMessage>(request); newReport.AssignedOfficers = new List <string>(); // select the team count based on count int count = request.ScaleOfDisaster switch { "low" => 2, "Medium" => 4, "High" => 6, _ => 2, }; // Fetch the assigning officer details List <OfficerDetails> officersList = new List <OfficerDetails>(); officersList.AddRange((request.MedicalAssistanceRequired) ? await _officerDetailsCollection.GetOfficerDetails("Medical", count) : new List <OfficerDetails>()); officersList.AddRange((request.TrafficPoliceAssistanceRequired) ? await _officerDetailsCollection.GetOfficerDetails("Traffic", count) : new List <OfficerDetails>()); officersList.AddRange((request.FireBrigadeAssistanceRequired) ? await _officerDetailsCollection.GetOfficerDetails("FireBrigade", count) : new List <OfficerDetails>()); officersList.AddRange(await _officerDetailsCollection.GetOfficerDetails("Law", count)); foreach (OfficerDetails officer in officersList) { try { // add the assign newReport.AssignedOfficers.Add(officer.ReferenceCode); officer.IsOfficerAssigned = true; bool updateResult = await _officerDetailsCollection.UpdateAsync(officer); //send notification introducing a pipeline or direct } catch (NullReferenceException) { continue; } } bool result = await _verifiedDisasterReportCollection.AddAsync(newReport); }