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);
        }