/// <summary>
 ///  This updates a data set.
 /// </summary>
 /// <param name="payLoad"></param>
 /// <param name="set"></param>
 /// <param name="queries"></param>
 private void HandleDataSetUpdate(DataPayLoad payLoad, DataSet set, IDictionary <string, string> queries)
 {
     try
     {
         _dataServices.UpdateDataSet(queries, set);
         payLoad.Queries     = queries;
         payLoad.Sender      = ToolBarModule.NAME;
         payLoad.PayloadType = DataPayLoad.Type.UpdateView;
         NotifyEventManager(_manager, payLoad);
     }
     catch (Exception e)
     {
         OnErrorExecuting?.Invoke(e.Message);
     }
 }
        protected override async Task <DataPayLoad> HandleSaveOrUpdate(DataPayLoad payLoad)
        {
            bool          result       = false;
            bool          isInsert     = false;
            ISupplierData supplierData = (ISupplierData)payLoad.DataObject;

            if (DataServices == null)
            {
                DataPayLoad nullDataPayLoad = new NullDataPayload();
                return(nullDataPayLoad);
            }
            switch (payLoad.PayloadType)
            {
            case DataPayLoad.Type.Update:
            {
                result = await DataServices.GetSupplierDataServices().SaveChanges(supplierData)
                         .ConfigureAwait(false);

                break;
            }

            case DataPayLoad.Type.Insert:
            {
                isInsert = true;
                result   = await DataServices.GetSupplierDataServices().Save(supplierData).ConfigureAwait(true);

                break;
            }
            }
            if (result)
            {
                payLoad.Sender      = ToolBarModule.NAME;
                payLoad.PayloadType = DataPayLoad.Type.UpdateView;
                CurrentPayload      = payLoad;
            }
            else
            {
                string message = isInsert ? "Error during the insert" : "Error during the update";
                OnErrorExecuting?.Invoke(message);
            }
            return(payLoad);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="payLoad"></param>
 /// <param name="dataSetList"></param>
 /// <param name="queries"></param>
 private void HandleDataSetListUpdate(DataPayLoad payLoad, IList <DataSet> dataSetList, IDictionary <string, string> queries)
 {
     foreach (DataSet set in dataSetList)
     {
         try
         {
             _dataServices.UpdateDataSet(queries, set);
             DataPayLoad newSet = (DataPayLoad)payLoad.Clone();
             newSet.HasDataSetList = false;
             newSet.HasDataSet     = true;
             payLoad.Sender        = ToolBarModule.NAME;
             payLoad.PayloadType   = DataPayLoad.Type.UpdateView;
             NotifyEventManager(_manager, payLoad);
         }
         catch (Exception e)
         {
             OnErrorExecuting?.Invoke(e.Message);
         }
     }
 }
Beispiel #4
0
 protected void ShowErrorMessage(string message)
 {
     OnErrorExecuting?.Invoke(message);
 }
Beispiel #5
0
 protected void SendError(string message)
 {
     OnErrorExecuting?.Invoke(message);
 }
Beispiel #6
0
        protected override async Task <DataPayLoad> HandleSaveOrUpdate(DataPayLoad payLoad)
        {
            bool          result       = false;
            bool          isInsert     = false;
            ISupplierData supplierData = payLoad.DataObject as ISupplierData;

            if (supplierData == null)
            {
                string message = (payLoad.PayloadType == DataPayLoad.Type.Insert) ? "Error during the insert" : "Error during the update";
                OnErrorExecuting?.Invoke(message);
                return(new DataPayLoad());
            }
            if (DataServices == null)
            {
                DataPayLoad nullDataPayLoad = new NullDataPayload();
                return(nullDataPayLoad);
            }
            var checkedSupplierData = await DataServices.GetSupplierDataServices().GetAsyncSupplierDo(supplierData.Value.NUM_PROVEE);

            if (checkedSupplierData.Value == null)
            {
                payLoad.PayloadType = DataPayLoad.Type.Insert;
            }
            switch (payLoad.PayloadType)
            {
            case DataPayLoad.Type.Update:
            {
                result = await DataServices.GetSupplierDataServices().SaveChanges(supplierData)
                         .ConfigureAwait(false);

                break;
            }

            case DataPayLoad.Type.Insert:
            {
                isInsert = true;
                result   = await DataServices.GetSupplierDataServices().Save(supplierData).ConfigureAwait(true);

                break;
            }

            case DataPayLoad.Type.UpdateInsertGrid:
            {
                result = true;
                if (payLoad.RelatedObject is IEnumerable <BranchesViewObject> )
                {
                    await UpdateGridAsync <BranchesViewObject, ProDelega>(payLoad);
                }
                else
                {
                    await UpdateGridAsync <ContactsViewObject, ProContactos>(payLoad);
                }
                break;
            }

            case DataPayLoad.Type.DeleteGrid:
            {
                if (payLoad.RelatedObject is IEnumerable <BranchesViewObject> branches)
                {
                    foreach (var branch in branches)
                    {
                        if (branch.IsDeleted)
                        {
                            // a delete bulk.
                            result = await DataServices.GetHelperDataServices().ExecuteAsyncDelete <BranchesViewObject, ProDelega>(branch);
                        }
                    }
                }
                ContactsViewObject contactsViewObject = payLoad.RelatedObject as ContactsViewObject;
                if (contactsViewObject != null)
                {
                    result = await DataServices.GetHelperDataServices().ExecuteAsyncDelete <ContactsViewObject, ProContactos>(contactsViewObject);
                }
                break;
            }
            }
            if (result)
            {
                payLoad.Sender               = ToolBarModule.NAME;
                payLoad.PayloadType          = DataPayLoad.Type.UpdateView;
                CurrentPayload               = new DataPayLoad();
                CurrentPayload.PayloadType   = DataPayLoad.Type.UpdateView;
                CurrentPayload.DataObject    = supplierData;
                CurrentPayload.Sender        = ToolBarModule.NAME;
                CurrentPayload.HasDataObject = true;
                CurrentPayload.Subsystem     = payLoad.Subsystem;
            }
            else
            {
                string message = isInsert ? "Error during the insert" : "Error during the update";
                OnErrorExecuting?.Invoke(message);
            }
            return(payLoad);
        }
Beispiel #7
0
        private async Task <DataPayLoad> HandleCommissionAgentSave(DataPayLoad payLoad)
        {
            bool result   = false;
            bool isInsert = false;

            Contract.Ensures(payLoad != null);
            Contract.Ensures(payLoad.DataObject != null);
            var ensureAgent = payLoad.DataObject as ICommissionAgent;

            Contract.Ensures(ensureAgent != null);

            ICommissionAgent agent = (ICommissionAgent)payLoad.DataObject;

            if (agent == null)
            {
                string message = (payLoad.PayloadType == DataPayLoad.Type.Insert) ? "Error during the insert" : "Error during the update";
                OnErrorExecuting?.Invoke(message);
            }

            switch (payLoad.PayloadType)
            {
            case DataPayLoad.Type.Insert:
            case DataPayLoad.Type.Update:
            {
                result = await _commissionAgentDataServices.SaveAsync(agent).ConfigureAwait(false);

                break;
            }

            case DataPayLoad.Type.UpdateInsertGrid:
            case DataPayLoad.Type.DeleteGrid:
            {
                result = true;
                var task1 = UpdateGridAsync <BranchesDto, COMI_DELEGA>(payLoad);
                var task2 = UpdateGridAsync <ContactsDto, CONTACTOS_COMI>(payLoad);
                var task3 = UpdateGridAsync <VisitsDto, VISITAS_COMI>(payLoad);

                IEnumerable <BranchesDto> branches = payLoad.RelatedObject as IEnumerable <BranchesDto>;
                IEnumerable <VisitsDto>   visits   = payLoad.RelatedObject as IEnumerable <VisitsDto>;
                try
                {
                    if (branches != null)
                    {
                        await task1;
                    }
                    else if (visits != null)
                    {
                        await task3;
                    }
                    else
                    {
                        await task2;
                    }
                }
                catch (System.Exception e)
                {
                    payLoad.Sender      = ToolBarModule.NAME;
                    payLoad.PayloadType = DataPayLoad.Type.UpdateError;
                    string message = isInsert ? "Error during the insert" : "Error during the update";
                    payLoad.ResultString = message;
                    OnErrorExecuting?.Invoke(message);
                    throw new DataLayerException("CommissionAgent Grid insertion exception", e);
                }
                break;
            }
            }

            if (result)
            {
                payLoad.Sender      = ToolBarModule.NAME;
                payLoad.PayloadType = DataPayLoad.Type.UpdateView;
                // it is really important to se the current payload to allow the refresh of control grids.
                CurrentPayload = payLoad;
            }
            else
            {
                payLoad.Sender      = ToolBarModule.NAME;
                payLoad.PayloadType = DataPayLoad.Type.UpdateError;
                string message = isInsert ? "Error during the insert" : "Error during the update";
                payLoad.ResultString = message;
                OnErrorExecuting?.Invoke(message);
                CurrentPayload = payLoad;
            }
            return(payLoad);
        }