Beispiel #1
0
        protected override void DeleteItem(DataPayLoad payLoad)
        {
            bool isDeleted = false;

            NotifyTaskCompletion.Create(DeleteAsync(payLoad),
                                        (sender, args) =>
            {
                if (sender is INotifyTaskCompletion <bool> taskCompletion)
                {
                    if (taskCompletion.IsFaulted)
                    {
                        DialogService?.ShowErrorMessage("Error during aving: " + taskCompletion.ErrorMessage);
                    }

                    if (!taskCompletion.IsSuccessfullyCompleted)
                    {
                        return;
                    }
                    isDeleted = true;
                }
            });

            if (isDeleted)
            {
                var dataPayLoad = new DataPayLoad
                {
                    Sender      = ViewModelUri.ToString(),
                    PayloadType = DataPayLoad.Type.UpdateView
                };
                EventManager.NotifyObserverSubsystem("ReservationRequests", dataPayLoad);
                UnregisterToolBar(payLoad.PrimaryKeyValue);
                DeleteRegion();
                DialogService?.ShowErrorMessage("Data deleted with success!");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Dictionary of events.
        /// </summary>
        /// <param name="eventDictionary"></param>
        private void OnChangedField(IDictionary <string, object> eventDictionary)
        {
            object      dataObject = DataObject;
            DataPayLoad payLoad    = BuildDataPayload(eventDictionary);

            ChangeFieldHandlerDo <ClientDto> handlerDo = new ChangeFieldHandlerDo <ClientDto>(EventManager,
                                                                                              DataSubSystem.ClientSubsystem);
            var fixedValue = DataObject;

            FixCreditCardInfo(ref fixedValue, ExpireMonth, ExpireYear);
            DataObject = fixedValue;

            if (string.IsNullOrEmpty(payLoad.PrimaryKeyValue))
            {
                payLoad.PrimaryKeyValue = PrimaryKeyValue;
            }

            SetBasePayLoad(eventDictionary, ref payLoad);
            if (CurrentOperationalState == DataPayLoad.Type.Insert)
            {
                handlerDo.OnInsert(payLoad, eventDictionary);
            }
            else
            {
                payLoad.PayloadType = DataPayLoad.Type.Update;
                handlerDo.OnUpdate(payLoad, eventDictionary);
            }
        }
        /// <summary>
        ///  TODO when it is called an insert.
        /// </summary>
        /// <param name="payload"></param>
        public void IncomingPayload(DataPayLoad payload)
        {
            if (payload.PayloadType == DataPayLoad.Type.Insert)
            {
                // just the active view shall do an insert for the helpers
                var activeView = RegionManager.Regions[RegionNames.TabRegion].ActiveViews.FirstOrDefault();
                if (activeView is UserControl control)
                {
                    if (control.DataContext is KarveViewModelBase baseViewModel)
                    {
                        if (ViewModelUri == baseViewModel.ViewModelUri)
                        {
                            NotifyTaskCompletion.Create(InsertEntity(payload), (ev, result) =>
                            {
                                if (result is INotifyTaskCompletion <bool> taskResult)

                                {
                                    if (taskResult.IsFaulted)
                                    {
                                        DialogService?.ShowErrorMessage("Error inserting:" + taskResult.ErrorMessage);
                                    }
                                }
                            });
                        }
                    }
                }
            }
        }
        public async Task WhenIntegrated_Should_LoadCreditCardExpirationData()
        {
            var clientService = _dataServices.GetClientDataServices();
            var sampleClient  = await clientService.GetPagedSummaryDoAsync(1, 2);

            var firstClient = sampleClient.FirstOrDefault();
            var clientData  = await clientService.GetDoAsync(firstClient.Code);

            clientData.Value.CreditCardExpiryMonth = "05";
            clientData.Value.CreditCardExpiryYear  = "27";

            var returnValue = await clientService.SaveAsync(clientData);

            var newClient = await clientService.GetDoAsync(firstClient.Code);

            var payLoad = new DataPayLoad();

            payLoad.DataObject      = clientData;
            payLoad.HasDataObject   = true;
            payLoad.PayloadType     = DataPayLoad.Type.Show;
            payLoad.PrimaryKeyValue = clientData.Value.NUMERO_CLI;
            _viewModel.IncomingPayload(payLoad);
            Assert.AreEqual("05", _viewModel.ExpireMonth);
            Assert.AreEqual("27", _viewModel.ExpireYear);
        }
        private void DoSaveCommand()
        {
            if (this.IsSaveEnabled)
            {
                this.CurrentSaveImagePath = KarveToolBarViewModel.currentSaveImage;
                this.IsSaveEnabled        = false;
                DataPayLoad payLoad = _careKeeper.GetScheduledPayload();
                if ((_careKeeper.GetScheduledPayloadType() == DataPayLoad.Type.Insert) || (_states == ToolbarStates.Insert))
                {
                    InsertDataCommand dataCommand = new InsertDataCommand(this._dataServices,
                                                                          this._careKeeper,
                                                                          this._eventManager,
                                                                          this._configurationService)
                    {
                        ValidationRules = this._validationRules
                    };
                    _careKeeper.Do(new CommandWrapper(dataCommand));
                    _states = ToolbarStates.None;
                }
                else
                {
                    SaveDataCommand dataCommand = new SaveDataCommand(this._dataServices, this._careKeeper,
                                                                      this._eventManager, this._configurationService);

                    payLoad             = _careKeeper.Do(new CommandWrapper(dataCommand));
                    payLoad.PayloadType = DataPayLoad.Type.UpdateView;

                    _eventManager.NotifyObserverSubsystem(payLoad.SubsystemName, payLoad);
                    //DeliverIncomingNotify(payLoad.Subsystem, payLoad);
                }
            }
            this.CurrentSaveImagePath = KarveToolBarViewModel.currentSaveImage;
            this.IsSaveEnabled        = false;
        }
        public void IncomingPayload(DataPayLoad dataPayLoad)
        {
            if (dataPayLoad == null)
            {
                return;
            }
            if (dataPayLoad.PayloadType != DataPayLoad.Type.Insert)
            {
                if ((dataPayLoad.Sender != null) && (dataPayLoad.Sender.Equals(ViewModelUri)))
                {
                    return;
                }
            }
            var interpreter = new PayloadInterpeter <IBookingIncidentData>();
            var currentId   = _dataIncidentService.NewId();

            interpreter.Init    = Init;
            interpreter.CleanUp = CleanUp;

            if (string.IsNullOrEmpty(PrimaryKeyValue))
            {
                PrimaryKeyValue = dataPayLoad.PrimaryKeyValue;
            }

            if (string.IsNullOrEmpty(PrimaryKeyValue))
            {
                return;
            }
            // i check what i have to do.
            OperationalState = interpreter.CheckOperationalType(dataPayLoad);
            // i act on the system and notify the subsystem
            interpreter.ActionOnPayload(dataPayLoad, PrimaryKeyValue, currentId, SubSystem,
                                        EventSubsystem.BookingSubsystemVm);
        }
        private static async void CalculateTimeLeft()
        {
            try
            {
                //Calculate time left in the day
                var remainingTimeString       = TimeSpan.FromHours(24) - DateTime.Now.TimeOfDay;
                var remainingHourInPercentage = Math.Round(((remainingTimeString.TotalHours / 24) * 100), 1);
                DataPayLoad = new DataPayLoad()
                {
                    Game  = "DAYACTIVE",
                    Event = "DISPLAY_TIME",
                    Data  = new Data()
                    {
                        Value = remainingHourInPercentage.ToString()
                    }
                };

                HttpResponseMessage response = await Connector.Client.PostAsJsonAsync(
                    "game_event", DataPayLoad);

                response.EnsureSuccessStatusCode();
            }
            catch (Exception ex)
            {
                string currentMethodName = ErrorHandling.GetCurrentMethodName();
                ErrorHandling.LogErrorToTxtFile(ex, currentMethodName);
            }
        }
 public override void ExecutePayload(IDataServices services, IEventManager manager, ref DataPayLoad payLoad)
 {
     DataServices   = services;
     EventManager   = manager;
     CurrentPayload = payLoad;
     ToolbarInitializationNotifier = NotifyTaskCompletion.Create <DataPayLoad>(HandleSaveOrUpdate(payLoad), ExecutedPayloadHandler);
 }
Beispiel #9
0
        public void Should_Insert_ANewItem()
        {
            ReservationRequestViewObject viewObject = new ReservationRequestViewObject()
            {
                NUMERO = "12190"
            };
            IReservationRequest reservationRequest = new ReservationRequest(viewObject);

            bool        isRegistered       = false;
            DataPayLoad currentDataPayLoad = null;
            var         requestService     = new Mock <IReservationRequestDataService>();

            requestService.Setup(x => x.GetNewDo(It.IsAny <string>())).Returns(reservationRequest);

            _eventManager.Setup(x => x.NotifyToolBar(It.IsAny <DataPayLoad>())).Callback <DataPayLoad>(x =>
            {
                isRegistered       = x.PayloadType == DataPayLoad.Type.RegistrationPayload;
                currentDataPayLoad = x;
            });
            _dataServices.Setup(x => x.GetReservationRequestDataService()).Returns(requestService.Object);
            var reservationRequestsView = new ReservationRequestsViewModel(_dataServices.Object, _interacionController.Object, _dialogService.Object, _eventManager.Object, _navigator.Object, null, null, _unityContainer.Object);

            // now i should arrange a new id and send to the reservation request view model.
            DataPayLoad payload = new DataPayLoad();

            payload.PayloadType   = DataPayLoad.Type.Insert;
            payload.DataObject    = reservationRequest;
            payload.HasDataObject = true;
            reservationRequestsView.IncomingPayload(payload);
            Assert.AreEqual(reservationRequestsView.DataObject.NUMERO, viewObject.NUMERO);
        }
        /// <summary>
        ///  Reverted current value.
        /// </summary>
        /// <param name="payLoad">This is the payload.</param>
        public override void Revert(DataPayLoad payLoad)
        {
            var tmp = CurrentValue;

            CurrentValue  = payLoad.DataObject as Dto;
            PreviousValue = tmp;
        }
Beispiel #11
0
        /// <summary>
        ///  Data payload
        /// </summary>
        /// <param name="payload">Payload to be used.</param>
        private void OnMailBoxHandler(DataPayLoad payload)
        {
            var newId = string.Empty;

            OperationalState = _payloadInterpeter.CheckOperationalType(payload);
            _payloadInterpeterReload.ActionOnPayload(payload, payload.PrimaryKeyValue, newId, DataSubSystem.BookingSubsystem, BookingModule.BookingSubSystem);
        }
Beispiel #12
0
 protected void RegisterView(ref DataPayLoad dataPayLoad)
 {
     Address = new Uri(new Uri("karve://helpers/"), UniqueId);
     // needs an unique.
     ViewModelUri           = Address;
     dataPayLoad.ObjectPath = Address;
 }
Beispiel #13
0
        public void Should_Call_AnInitPayload()
        {
            // arrange
            var initValue    = 0;
            var cleanUpValue = 0;

            var payLoad = new DataPayLoad
            {
                DataObject      = new OfficeDtos(),
                PrimaryKeyValue = "3893893",
                Subsystem       = DataSubSystem.OfficeSubsystem,
                SubsystemName   = MasterModuleConstants.OfficeSubSytemName,
                PayloadType     = DataPayLoad.Type.Show
            };
            var parser = new PayloadInterpeter <OfficeDtos>
            {
                Init    = (value, packet, insertion) => { initValue++; },
                CleanUp = (key, system, name) => { cleanUpValue++; }
            };

            // act
            parser.ActionOnPayload(payLoad, "3893893", "838393", DataSubSystem.OfficeSubsystem, MasterModuleConstants.OfficeSubSytemName);
            // assert.
            Assert.AreEqual(initValue, 1);
            Assert.AreEqual(cleanUpValue, 0);
        }
        private async Task <bool> HandleReservationSaveOrUpdate(DataPayLoad payLoad)
        {
            var reservationService   = DataServices.GetReservationRequestDataService();
            var dataObject           = payLoad.DataObject;
            var currentWorkingObject = dataObject;
            var result = false;

            if (dataObject is KarveDataServices.IReservationRequest req)
            {
                currentWorkingObject = req.Value;
            }
            if (currentWorkingObject is ReservationRequestDto currentDto)
            {
                // hwew we are sure that we are saving.
                var currentValue = await reservationService.GetDoAsync(currentDto.NUMERO).ConfigureAwait(false);

                if ((currentValue == null))
                {
                    payLoad.PayloadType = DataPayLoad.Type.Insert;
                }
                currentValue.Value = currentDto;
                switch (payLoad.PayloadType)
                {
                case DataPayLoad.Type.Insert:
                case DataPayLoad.Type.Update:
                {
                    result = await reservationService.SaveAsync(currentValue).ConfigureAwait(false);

                    break;
                }
                }
            }
            return(result);
        }
Beispiel #15
0
 protected bool IsForMe <DomainType>(DataPayLoad dataPayLoad, Func <DomainType, bool> fieldCompare) where DomainType : class
 {
     // is it null?
     if (dataPayLoad == null)
     {
         return(false);
     }
     // is it sent by myself?
     if ((dataPayLoad.Sender != null) && (dataPayLoad.Sender.Equals(ViewModelUri)))
     {
         return(false);
     }
     if (dataPayLoad.DataObject == null)
     {
         return(false);
     }
     if (PrimaryKeyValue.Length > 0)
     {
         var request = dataPayLoad.DataObject as DomainType;
         if (request == null)
         {
             return(false);
         }
         return(fieldCompare(request));
     }
     return(true);
 }
Beispiel #16
0
        protected override void DeleteItem(DataPayLoad payLoad)
        {
            NotifyTaskCompletion.Create <bool>(this.DeleteAsync(payLoad),
                                               ev: (sender, args) =>
            {
                if (!(sender is INotifyTaskCompletion <bool> taskCompletion))
                {
                    return;
                }
                if (taskCompletion.IsFaulted)
                {
                    DialogService?.ShowErrorMessage("Error during deleting the invoice");
                }

                if (!taskCompletion.IsSuccessfullyCompleted)
                {
                    return;
                }
                var dataPayLoad = new DataPayLoad()
                {
                    Sender      = ViewModelUri.ToString(),
                    PayloadType = DataPayLoad.Type.UpdateView
                };
                EventManager.NotifyObserverSubsystem(InvoiceModule.InvoiceSubSystem, dataPayLoad);
                UnregisterToolBar(payLoad.PrimaryKey);

                DeleteRegion();
            });
        }
        /// <summary>
        ///  This is to save or update the data contained in the payload.
        /// </summary>
        /// <param name="payLoad"></param>
        /// <returns></returns>
        protected override async Task <DataPayLoad> HandleSaveOrUpdate(DataPayLoad payLoad)
        {
            DataPayLoad currentPayLoad = payLoad;

            if (currentPayLoad.HasDataObject)
            {
                SetModification(ref currentPayLoad);
                Dto currentDto = currentPayLoad.DataObject as Dto;
                if (currentDto == null)
                {
                    currentDto = CurrentValue;
                }
                bool value = await _saver.SaveDto(currentDto);

                if (!value)
                {
                    State = "Error in insertion/update";
                }
                else
                {
                    HelperView.Add(currentDto);
                }
                SaveState = value;
                State     = "";
            }
            return(currentPayLoad);
        }
Beispiel #18
0
        protected override void NewItem()
        {
            string name = "Nueva Empresa";
            //KarveLocale.Properties.Resources.CompanyControlViewModel_NewItem_NuevaEmpresa;
            string companyId     = _companyDataServices.GetNewId();
            string viewNameValue = name + "." + companyId;
            // here shall be added to the region
            var navigationParameters = new NavigationParameters
            {
                { "id", companyId },
                { ScopedRegionNavigationContentLoader.DefaultViewName, viewNameValue }
            };
            var uri = new Uri(typeof(CompanyInfoView).FullName + navigationParameters, UriKind.Relative);

            RegionManager.RequestNavigate("TabRegion", uri);
            DataPayLoad currentPayload = BuildShowPayLoadDo(viewNameValue);

            currentPayload.Subsystem       = DataSubSystem.CompanySubsystem;
            currentPayload.PayloadType     = DataPayLoad.Type.Insert;
            currentPayload.PrimaryKeyValue = companyId;
            currentPayload.DataObject      = _companyDataServices.GetNewCompanyDo(companyId);
            currentPayload.HasDataObject   = true;
            currentPayload.Sender          = EventSubsystem.CompanySummaryVm;
            EventManager.NotifyObserverSubsystem(MasterModuleConstants.CompanySubSystemName, currentPayload);
        }
Beispiel #19
0
        public void SaveViewCommand(object key)
        {
            bool isSaved = false;

            _reservationRequest.Value = DataObject;
            NotifyTaskCompletion.Create(_dataReservationService.SaveAsync(_reservationRequest), (sender, args) =>
            {
                if (sender is INotifyTaskCompletion <bool> taskCompletion)
                {
                    if (taskCompletion.IsFaulted)
                    {
                        DialogService?.ShowErrorMessage("Error during saving: " + taskCompletion.ErrorMessage);
                    }
                    if (taskCompletion.IsSuccessfullyCompleted)
                    {
                        isSaved = true;
                    }
                }
            });
            if (isSaved)
            {
                var dataPayLoad = new DataPayLoad
                {
                    Sender      = ViewModelUri.ToString(),
                    PayloadType = DataPayLoad.Type.UpdateView
                };
                EventManager.NotifyObserverSubsystem("ReservationRequests", dataPayLoad);
                DialogService?.ShowErrorMessage("Data saved with success!");
            }
        }
        private void OnChangedField(IDictionary <string, object> eventDictionary)
        {
            DataPayLoad payLoad = BuildDataPayload(eventDictionary);

            payLoad.Subsystem     = DataSubSystem.SupplierSubsystem;
            payLoad.SubsystemName = MasterModuleConstants.ProviderSubsystemName;
            payLoad.PayloadType   = DataPayLoad.Type.Update;
            ChangeFieldHandlerDo <ISupplierData> handlerDo = new ChangeFieldHandlerDo <ISupplierData>(EventManager,
                                                                                                      DataSubSystem.SupplierSubsystem);

            var fieldName = string.Empty;

            SetBasePayLoad(eventDictionary, ref payLoad);
            // FIXME: replace conditional with polymorphism.
            if (CurrentOperationalState == DataPayLoad.Type.Insert)
            {
                payLoad.PayloadType = DataPayLoad.Type.Insert;
                handlerDo.OnInsert(payLoad, eventDictionary);
            }
            else
            {
                payLoad.PayloadType = DataPayLoad.Type.Update;
                handlerDo.OnUpdate(payLoad, eventDictionary);
            }
        }
 /// <summary>
 ///  Update summary.
 /// </summary>
 /// <param name="payLoad">Payload to be updated.</param>
 /// <returns></returns>
 public override bool UpdateEntity(DataPayLoad payLoad)
 {
     State     = BaseHelperViewModel.UpdateState;
     SaveState = false;
     SaveItem(payLoad);
     Update();
     return(SaveState);
 }
Beispiel #22
0
 /// <summary>
 ///  This execute a payload.
 /// </summary>
 /// <param name="services">Data services to be used for executing the payload</param>
 /// <param name="manager">Manager to be used for sending messages to the view model</param>
 /// <param name="payLoad">Payload to be used for sending it.</param>
 public override void ExecutePayload(IDataServices services, IEventManager manager, ref DataPayLoad payLoad)
 {
     _commissionAgentDataServices = services.GetCommissionAgentDataServices();
     DataServices            = services;
     _payload                = payLoad;
     EventManager            = manager;
     _initializationNotifier = NotifyTaskCompletion.Create <DataPayLoad>(HandleCommissionAgentSave(_payload), ExecutedPayloadHandler);
 }
 /// <summary>
 /// Execute the payload when the user press to save and it notifies the
 /// </summary>
 /// <param name="services">Data services are used to store the data.</param>
 /// <param name="manager">Event manager is used to notify the caller and refresh data.</param>
 /// <param name="payLoad">Payload to be updated</param>
 public override void ExecutePayload(IDataServices services, IEventManager manager, ref DataPayLoad payLoad)
 {
     CurrentEventManager           = manager;
     CurrentPayload                = payLoad;
     DataServices                  = services ?? throw new ArgumentNullException($"Cannot save without DataServices");
     ToolbarInitializationNotifier =
         NotifyTaskCompletion.Create <DataPayLoad>(HandleSaveOrUpdate(payLoad), ExecutedPayloadHandler);
 }
Beispiel #24
0
        private void CheckData(DataPayLoad data)
        {
            //  var currentValue = data.CollectionData[3];
            var currentType = data.PayloadType;

            //Assert.AreEqual(currentValue, 3);
            Assert.AreEqual(currentType, DataPayLoad.Type.Insert);
        }
Beispiel #25
0
        /// <summary>
        ///  In this case we dont know the type so the resposability will be of the view model.
        /// </summary>
        /// <param name="payLoad">Payload</param>
        /// <returns></returns>
        protected override async Task <DataPayLoad> HandleSaveOrUpdate(DataPayLoad payLoad)
        {
            var  dataObject = payLoad.DataObject;
            Type type       = dataObject.GetType();
            await Task.Delay(1);

            return(payLoad);
        }
Beispiel #26
0
        /// <summary>
        ///  Delete a company given its primary key
        /// </summary>
        /// <param name="primaryKey">Delete a single company</param>
        /// <param name="payLoad">Payload received</param>
        /// <returns></returns>
        public override async Task <bool> DeleteAsync(string primaryKey, DataPayLoad payLoad)
        {
            var data = await _companyDataServices.GetAsyncCompanyDo(primaryKey);

            var retValue = await _companyDataServices.DeleteCompanyAsyncDo(data);

            return(retValue);
        }
Beispiel #27
0
 /// <summary>
 /// This execute the payload and notify the event manager
 /// </summary>
 /// <param name="services">Services to be used</param>
 /// <param name="manager">Manager to be notified</param>
 /// <param name="payLoad">Payload to execute.</param>
 public override void ExecutePayload(IDataServices services, IEventManager manager, ref DataPayLoad payLoad)
 {
     _dataServices           = services.GetSupplierDataServices();
     _payload                = payLoad;
     EventManager            = manager;
     DataServices            = services;
     _initializationNotifier = NotifyTaskCompletion.Create <DataPayLoad>(HandleSaveOrUpdate(_payload), ExecutedPayloadHandler);
 }
Beispiel #28
0
        protected async void HandlePayLoadMessage(DataPayLoad payLoad)
        {
            if (payLoad.ObjectPath == Address)
            {
                switch (payLoad.PayloadType)
                {
                case DataPayLoad.Type.RevertChanges:
                {
                    Revert(payLoad);
                    break;
                }

                case DataPayLoad.Type.Delete:
                {
                    bool deleted = await DeleteEntity(payLoad).ConfigureAwait(false);

                    if (!deleted)
                    {
                        DialogService?.ShowErrorMessage("Cannot delete helper entity");
                    }
                    else
                    {
                        DialogService?.ShowMessage("Information", "Line deleted with success");
                    }
                    break;
                }

                case DataPayLoad.Type.Insert:
                {
                    bool inserted = await InsertEntity(payLoad).ConfigureAwait(false);

                    if (!inserted)
                    {
                        DialogService?.ShowErrorMessage("Cannot insert helper entity");
                    }
                    else
                    {
                        DialogService?.ShowMessage("Information", "Line inserted with success");
                    }
                    break;
                }

                case DataPayLoad.Type.Update:
                {
                    bool update = UpdateEntity(payLoad);
                    if (!update)
                    {
                        MessageBox.Show("Cannot update helper entity");
                    }
                    else
                    {
                        DialogService?.ShowMessage("Information", "Line updated with success");
                    }
                    break;
                }
                }
            }
        }
Beispiel #29
0
        /// <summary>
        ///  Register the toolbar.
        /// </summary>
        protected void RegisterToolBar()
        {
            // each module notify the toolbar.
            var payLoad = new DataPayLoad();

            SetRegistrationPayLoad(ref payLoad);
            payLoad.PayloadType = DataPayLoad.Type.RegistrationPayload;
            EventManager.NotifyToolBar(payLoad);
        }
Beispiel #30
0
        /// <summary>
        ///  This method register a subsystem.
        /// </summary>
        private void RegisterSubsystem()
        {
            DataPayLoad payLoad = new DataPayLoad();

            payLoad.PayloadType = DataPayLoad.Type.RegistrationPayload;
            payLoad.Subsystem   = DataSubSystem.HelperSubsytsem;
            RegisterView(ref payLoad);
            EventManager.NotifyToolBar(payLoad);
        }