public async Task <bool> CreateAsync(object request) { ReportDisasterRequest request_ = (ReportDisasterRequest)request; ClassValueCopier copier = new ClassValueCopier(); ReportedDisaster newReport = copier.ConvertAndCopy <ReportedDisaster, ReportDisasterRequest>(request_); newReport.CreatedBy = request_.ReportedBy; newReport.IsVerfied = false; bool result = await _disasterCollection.AddAsync(newReport); if (result) { //Implemented:: //create the message VerifyDisasterRequest verifyDisaster = copier.ConvertAndCopy <VerifyDisasterRequest, ReportedDisaster>(newReport); string data = JsonConvert.SerializeObject(verifyDisaster); //publishing the message await Mqtt.MqttPublish("RSCD/Server/Disaster/Verification", data); //return the http response //TO DO:: //1.create the message //2.push to the queue //3.return the http response } return(result); }
public async Task <bool> CloseDisaster(GeneralFetchRequest request) { ReportedDisaster oldDisaster = await _disasterCollection.GetAsync(request.Code); var copier = new ClassValueCopier(); var newDisaster = copier.ConvertAndCopy(request, oldDisaster); newDisaster.IsClosed = true; return(await _disasterCollection.UpdateAsync(newDisaster)); }
public async Task <bool> UpdateDocumentAsync(object request = null) { VerifiedDisasterRequest request_ = (VerifiedDisasterRequest)request; ReportedDisaster oldDisaster = await _disasterCollection.GetAsync(request_.ReferenceCode); var copier = new ClassValueCopier(); ReportedDisaster newDisaster = copier.ConvertAndCopy(request_, oldDisaster); newDisaster.LastUpdatedBy = request_.VerifiedBy; newDisaster.IsClosed = false; bool result = await _disasterCollection.UpdateAsync(newDisaster); if (result && newDisaster.IsInfoTrue) { VerifiedDisasterMessage verifiedDisaster = copier.ConvertAndCopy <VerifiedDisasterMessage, ReportedDisaster>(newDisaster); string data = JsonConvert.SerializeObject(verifiedDisaster); await Mqtt.MqttPublish("RSCD/Message/Disaster/Verified", data); } return(result); }
public async Task <bool> AddAsync(ReportedDisaster document) { try { Random _rdm = new Random(); int id2 = _rdm.Next(000000, 1000000); int id1 = Convert.ToInt32(DateTime.Now.ToString("mmssff")); var id = id1 | id2; document.ReferenceCode = _collectionCodePrefix + id.ToString(); document.CreatedAt = DateTime.Now.ToString(); document.LastUpdatedAt = ""; document.IsActive = true; await _context.ReportedDisasterCollection.InsertOneAsync(document); return(true); } catch (Exception ex) { throw ex; } }