Exemplo n.º 1
0
        public async Task Save()
        {
            string _Result = "OK";

            IsWorking = true;
            if (!string.IsNullOrEmpty(ImageUrl.ToString()))
            {
                if (!ImageUrl.ToString().Contains(RuntimeSettings.ImagePlaceholderName))
                {
                    if (!ImageUrl.ToString().Contains("Uri"))
                    {
                        try
                        {
                            string imgPath = ImageUrl.ToString().Split(':')[1].Trim();
                            _Result = await _this.Edit(imgPath);
                        }
                        catch (Exception ex)
                        {
                            _Result = ex.Message;
                        }
                    }
                }
            }
            if (_Result == "OK")
            {
                _Result = await ProcessAttachmentsVm.Save(partId : _this.PartId);

                IsWorking = false;
                if (_Result == "OK")
                {
                    IsWorking = false;
                    await Application.Current.MainPage.DisplayAlert("Zapisano", "Zapis zakończony powodzeniem!", "OK");
                }
                else
                {
                    IsWorking = false;
                    await Application.Current.MainPage.DisplayAlert("Błąd zapisu", $"Zapis załączników zakończony błędem: {_Result}", "OK");
                }
            }
            else
            {
                IsWorking = false;
                await Application.Current.MainPage.DisplayAlert("Błąd zapisu", $"Zapis danych części zakończony błędem: {_Result}", "OK");
            }
        }
Exemplo n.º 2
0
        public async Task <bool> IsDirty()
        {
            List <Task <bool> > tasks = new List <Task <bool> >();

            try
            {
                Task <bool> AttachmentIsDirtyTask;

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