public async Task <bool> IsDirty() { //Logger.Info("IsDirty: is starting"); List <Task <bool> > tasks = new List <Task <bool> >(); try { Task <bool> ActionIsDirtyTask; Task <bool> PartIsDirtyTask; Task <bool> AttachmentIsDirtyTask; if (ActionListVm != null) { ActionIsDirtyTask = Task.Run(() => ActionListVm.IsDirty()); tasks.Add(ActionIsDirtyTask); } if (AssignedPartsVm != null) { PartIsDirtyTask = Task.Run(() => AssignedPartsVm.IsDirty()); tasks.Add(PartIsDirtyTask); } if (ProcessAttachmentsVm != null) { AttachmentIsDirtyTask = Task.Run(() => ProcessAttachmentsVm.IsDirty()); tasks.Add(AttachmentIsDirtyTask); } if (tasks.Any()) { IEnumerable <bool> res = await Task.WhenAll <bool>(tasks); if (res.Any(r => r == true)) { return(true); } else { return(false); } } return(false); } catch (Exception ex) { //Logger.Error(ex, "IsDirty: {ex}"); Static.Functions.CreateError(ex, "IsDirty throws error", "IsDirty", this.GetType().Name); return(false); } }
public async Task <string> Validate(bool EndValidation = false) { string _res = "OK"; if (EndValidation) { if (RequireInitialDiagnosis) { if (string.IsNullOrEmpty(_thisProcess.InitialDiagnosis)) { _res = "Pole Wstępne rozpoznanie nie może być puste. Uzupełnij wstępne rozpoznanie!"; } else if (string.IsNullOrEmpty(_thisProcess.RepairActions)) { _res = "Pole Czynności naprawcze nie może być puste. Uzupełnij opis czynności naprawczych!"; } } } if (_thisProcess.PlaceId == 0) { _res = "Nie wybrano zasobu! Wybierz zasób z listy rozwijanej!"; } if (_thisProcess.ActionTypeId == 0) { _res = "Nie wybrano typu zgłoszenia! Wybierz typ złgoszenia z listy rozwijanej!"; } if (_res == "OK") { _res = await ValidateQr(EndValidation); if (_res == "OK" && EndValidation && ActionsApplicable) { _res = ActionListVm.Validate(); } if (_res == "OK" && PartsApplicable) { _res = AssignedPartsVm.Validate(); } } return(_res); }
public async Task <string> End(bool toClose = false, bool toPause = false, int?abandonReason = null) { string _Result = "OK"; IsWorking = true; try { string prevStatus = _thisProcess.Status; if (toClose) { _thisProcess.FinishedOn = DateTime.Now; _thisProcess.FinishedBy = RuntimeSettings.UserId; _thisProcess.Status = "Zakończony"; _Result = await _thisProcess.Edit(); if (!_Result.Equals("OK")) { _thisProcess.Status = prevStatus; } } else { if (toPause) { _thisProcess.Status = "Wstrzymany"; _Result = await _thisProcess.Edit(); if (!_Result.Equals("OK")) { _thisProcess.Status = prevStatus; } } } // Close handling now if (_Result == "OK") { prevStatus = _this.Status; _this.FinishedOn = DateTime.Now; _this.Status = "Zakończony"; if (RequireInitialDiagnosis) { _this.Output = _thisProcess.RepairActions; } else { _this.Output = _thisProcess.Output; } _Result = await _this.Edit(); if (_Result == "OK" && ActionsApplicable && HasActions) { //Save actions if there are any _Result = await ActionListVm.Save(_this.HandlingId, _thisProcess.ProcessId, abandonReason); } if (_Result == "OK" && PartsApplicable) { _Result = await AssignedPartsVm.Save(_this.ProcessId, _this.PlaceId); } RuntimeSettings.CurrentUser.IsWorking = false; if (!_Result.Equals("OK")) { _this.Status = prevStatus; RuntimeSettings.CurrentUser.IsWorking = true; } } OnPropertyChanged(nameof(NextState)); OnPropertyChanged(nameof(NextStateColor)); OnPropertyChanged(nameof(IsOpen)); OnPropertyChanged(nameof(IsClosable)); OnPropertyChanged(nameof(Icon)); } catch (Exception ex) { Static.Functions.CreateError(ex, "No connection", nameof(this.End), this.GetType().Name); } IsWorking = false; return(_Result); }
public async Task <string> Save() { string _Result = "OK"; IsWorking = true; try { // Taking care of process if (_Result == "OK") { if (!this.IsProcessOpen) { //if the process doesn't exist yet, open it now _thisProcess.CreatedBy = RuntimeSettings.UserId; _thisProcess.TenantId = RuntimeSettings.TenantId; _thisProcess.StartedBy = RuntimeSettings.UserId; _thisProcess.StartedOn = DateTime.Now; _thisProcess.Status = "Rozpoczęty"; _thisProcess.CreatedOn = DateTime.Now; _Result = await _thisProcess.Add(); IsProcessOpen = true; } else { // There must be new process edit logic.. if (_thisProcess.Status == "Wstrzymany" || _thisProcess.Status == "Planowany") { _thisProcess.Status = "Rozpoczęty"; } if (_thisProcess.StartedOn == null) { //it's planned process, open but NOT started yet.. _thisProcess.StartedOn = DateTime.Now; _thisProcess.StartedBy = RuntimeSettings.CurrentUser.UserId; if (Type.ClosePreviousInSamePlace != null) { if ((bool)Type.ClosePreviousInSamePlace) { Task.Run(() => _thisProcess.CompleteAllProcessesOfTheTypeInThePlace("Zamknięte ponieważ nowsze zgłoszenie tego typu zostało rozpoczęte")); } } } _Result = await _thisProcess.Edit(); } // Taking care of handling if (_Result == "OK") { if (this.IsNew) { //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 HandlingKeeper Handlings = new HandlingKeeper(); _Result = await Handlings.CompleteUsersHandlings(); if (_Result == "OK") { _this.StartedOn = DateTime.Now; _this.UserId = RuntimeSettings.UserId; _this.TenantId = RuntimeSettings.TenantId; _this.Status = "Rozpoczęty"; _this.ProcessId = _thisProcess.ProcessId; _Result = await _this.Add(); IsNew = false; OnPropertyChanged(nameof(NextState)); OnPropertyChanged(nameof(NextStateColor)); } } else { if (_this.Status == "Wstrzymany" || _this.Status == "Planowany") { _this.Status = "Rozpoczęty"; } _Result = await _this.Edit(); OnPropertyChanged(nameof(NextState)); OnPropertyChanged(nameof(NextStateColor)); } if (_Result == "OK" && ActionsApplicable && HasActions) { //Save actions if there are any _Result = await ActionListVm.Save(_this.HandlingId, _thisProcess.ProcessId); } if (_Result == "OK" && PartsApplicable) { _Result = await AssignedPartsVm.Save(_thisProcess.ProcessId, _thisProcess.PlaceId); } if (_Result == "OK") { _Result = await ProcessAttachmentsVm.Save(_thisProcess.ProcessId); } RuntimeSettings.CurrentUser.IsWorking = true; OnPropertyChanged(nameof(Icon)); } } } catch (Exception ex) { _Result = ex.Message; } IsWorking = false; return(_Result); }