public Undertaker(BurialModelOutPut burialOutPut, IBurialService apiBurial) { InitializeComponent(); _apiBurial = apiBurial; BindingContext = _undertakerViewModel = new UndertakerViewModel(burialOutPut, _apiBurial); lblUndertakerName.Text = burialOutPut.Undertaker; lblAccessCounter.Text = burialOutPut.AccessCount.ToString(); lblDeceasedDetails.Text = burialOutPut.DeceasedDetails; _sqLiteConnection = DependencyService.Get <ISQLite>().GetConnection(); }
public UndertakerViewModel(BurialModelOutPut burialOutPut, IBurialService apiBurial) { _burialOutPut = burialOutPut; _sqLiteConnection = DependencyService.Get <ISQLite>().GetConnection(); _sqLiteConnection.CreateTable <Burial>(); if (_burialOutPut.BurialApplication != 0) { _burialApplication = _burialOutPut.BurialApplication; _supervisor = new SupervisorModel { CemeteryId = burialOutPut.CemeteryId, SupervisorId = burialOutPut.SupervisorId, Name = burialOutPut.Name, Surname = burialOutPut.Surname }; } _apiBurial = apiBurial; }
private void HandleScanResult(ZXing.Result result, long?burialAppId) { if (result != null && !string.IsNullOrEmpty(result.Text)) // Success { int number; var resultValue = result.Text.TrimStart('0'); bool isNumber = int.TryParse(resultValue, out number); if (isNumber) { if (long.Parse(resultValue) == burialAppId || burialAppId == null) { var scannedItem = long.Parse(resultValue); var currentDateTime = DateTime.Now; ////check if burial application expired var expiredApplication = (from burial in _sqLiteConnection.Table <Burial>() where burial.BurialApplication.Equals(scannedItem) select burial).FirstOrDefault(); if (expiredApplication == null) { Application.Current.MainPage.DisplayAlert("Warning", "Either the application expired or does not exist, Contact the municipality.", "OK"); } else { if (expiredApplication.OptDate == null) //proceed { var supervisorId = SupervisorId; if (true) //todo: vaidate cemetery check ... { var qBurials = from row in _sqLiteConnection.Table <Burial>() where row.BurialApplication == scannedItem select new BurialModelAccessCounterOutput() { AccessCounter = row.AccessCounter, OtpDate = row.OptDate, DeceasedDetails = row.DeceasedDetails }; var r = qBurials.FirstOrDefault(); if (r == null) { Application.Current.MainPage.DisplayAlert("Error", "Error api connection", "OK"); } else { var burialAppEdit = new BurialModelAccessCounterInput { BurialApplication = scannedItem, CemeterySupervisorId = (int?)supervisorId }; var query = (from row in _sqLiteConnection.Table <Burial>() where row.BurialApplication == burialAppEdit.BurialApplication select row).FirstOrDefault(); query.AccessCounter = query.AccessCounter + 1; _sqLiteConnection.ExecuteScalar <Burial>( "UPDATE Burial Set AccessCounter = ? WHERE BurialApplication = ?", query.AccessCounter, query.BurialApplication); _burialOutPut = new BurialModelOutPut() { Undertaker = query.Undertaker, AccessCount = query.AccessCounter, BurialApplication = query.BurialApplication, CemeteryId = _supervisor.CemeteryId, DeceasedDetails = query.DeceasedDetails, SupervisorId = query.CemeterySupervisorId, Name = _supervisor.Name, Surname = _supervisor.Surname, SupervisorName = _supervisor.Fullname, Cemetery = query.Cemetery }; } } } else { if (expiredApplication.OptDate == null) { Application.Current.MainPage.DisplayAlert("Warning", "Access Code " + expiredApplication.BurialApplication + " expired.", "OK"); return; } var otpDate = (DateTime)expiredApplication.OptDate; Application.Current.MainPage.DisplayAlert("Warning", "Access Code " + expiredApplication.BurialApplication + " expired. " + expiredApplication.OptDate + " (" + (currentDateTime - otpDate).Days + " day ago)", "OK"); } } } else { Application.Current.MainPage.DisplayAlert("Error", "access denied", "OK"); } } else { Application.Current.MainPage.DisplayAlert("Error", "Scanned code not allowed!", "OK"); } } else // Canceled { Reload(); } }