private async Task Start(bool resurrection = false) { string _Res = "OK"; try { _Res = await Validate(); if (_Res == "OK") { if (ActionTypes.Items.Any(at => at.ActionTypeId == _this.ActionTypeId)) { if (ActionTypes.Items.FirstOrDefault(at => at.ActionTypeId == _this.ActionTypeId).ClosePreviousInSamePlace == true) { Task.Run(() => _this.CompleteAllProcessesOfTheTypeInThePlace("Zamknięte ponieważ nowsze zgłoszenie tego typu zostało rozpoczęte")); } } // Taking care of handling //this handling is completely new, create it //But first, let's make sure User don't have any other open handligs elsewhere. If he does, let's complete them first HandlingsKeeper Handlings = new HandlingsKeeper(); _Res = await Handlings.CompleteUsersHandlings(); if (_Res == "OK") { Handling h = new Handling(); h.StartedOn = DateTime.Now; h.UserId = RuntimeSettings.UserId; h.TenantId = RuntimeSettings.TenantId; h.Status = "Rozpoczęty"; h.ProcessId = _this.ProcessId; h.PlaceId = _this.PlaceId; h.ActionTypeId = _this.ActionTypeId; if (!await h.Add()) { _Res = "Wystąpił problem przy tworzeniu obsługi tego zgłoszenia dla bieżącego użytkownika"; } if (_Res == "OK") { //_Res = await SaveActions(h.HandlingId); //if (_Res == "OK") //{ if (!resurrection) { cmbStartedBy.SelectedValue = RuntimeSettings.UserId; txtStartedOn.Value = DateTime.Now; } cmbStatus.SelectedIndex = cmbStatus.FindStringExact("Rozpoczęty"); _Res = await Save(); //} } } } if (_Res != "OK") { MessageBox.Show($"Napotkano błąd przy próbie rozpoczęcia zgłoszenia. Szczegóły: {_Res}", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show($"Napotkano błąd przy próbie rozpoczęcia zgłoszenia. Szczegóły: {_Res}", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private async Task End() { string _Res = "OK"; try { _Res = await Validate(true); if (_Res == "OK") { // Taking care of handling HandlingsKeeper hk = new HandlingsKeeper(); await hk.Refresh($"UserId={RuntimeSettings.UserId} and ProcessId={_this.ProcessId}"); Handling h; if (hk.Items.Any(i => i.Status == "Rozpoczęty")) { //User has a handling that is started, let's use it h = hk.Items.FirstOrDefault(i => i.Status == "Rozpoczęty"); h.PlaceId = _this.PlaceId; h.Status = "Zakończony"; h.ActionTypeId = _this.ActionTypeId; h.FinishedOn = DateTime.Now; h.Output = "Obsługa utworzona na komputerze"; _Res = await h.Edit(); } else { h = new Handling(); h.StartedOn = DateTime.Now; h.UserId = RuntimeSettings.UserId; h.TenantId = RuntimeSettings.TenantId; h.ProcessId = _this.ProcessId; h.PlaceId = _this.PlaceId; h.Status = "Zakończony"; h.FinishedOn = DateTime.Now; h.ActionTypeId = _this.ActionTypeId; h.Output = "Obsługa utworzona na komputerze"; if (!await h.Add()) { _Res = "Wystąpił problem przy tworzeniu obsługi tego zgłoszenia dla bieżącego użytkownika"; } } if (_Res == "OK") { _Res = await SaveActions(h.HandlingId); if (_Res == "OK") { cmbFinishedBy.SelectedValue = RuntimeSettings.UserId; txtFinishedOn.Value = DateTime.Now; cmbStatus.SelectedIndex = cmbStatus.FindStringExact("Zakończony"); _Res = await Save(); } } } if (_Res != "OK") { MessageBox.Show($"Napotkano błąd przy próbie zakończenia zgłoszenia. Szczegóły: {_Res}", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show($"Napotkano błąd przy próbie rozpoczęcia zgłoszenia. Szczegóły: {_Res}", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } }