Exemplo n.º 1
0
        protected override async Task <DataPayLoad> HandleSaveOrUpdate(DataPayLoad payLoad)
        {
            bool      result     = false;
            bool      isInsert   = payLoad.PayloadType == DataPayLoad.Type.Insert;
            ClientDto clientData = payLoad.DataObject as ClientDto;

            // pre: DataServices and vehicle shall be present.
            if ((DataServices == null))
            {
                DataPayLoad nullDataPayLoad = new NullDataPayload();
                return(nullDataPayLoad);
            }
            if (clientData == null)
            {
                string message = (isInsert) ? "Error during the insert" : "Error during the update";
                SendError(message);
                // i return a null payload.
                return(new NullDataPayload());
            }
            // FIXME: check for the law of demeter.
            var clientDo = await DataServices.GetClientDataServices().GetDoAsync(clientData.NUMERO_CLI);

            if (clientDo == null)
            {
                payLoad.PayloadType = DataPayLoad.Type.Insert;
            }
            AbstractDomainWrapperFactory factory = AbstractDomainWrapperFactory.GetFactory(DataServices);
            IClientData clientWrapper            = await factory.CreateClientAsync(clientData).ConfigureAwait(false);

            clientWrapper.Value = clientData;
            result = await DataServices.GetClientDataServices().SaveAsync(clientWrapper).ConfigureAwait(false);             if (result)
            {
                payLoad.Sender               = ToolBarModule.NAME;
                payLoad.PayloadType          = DataPayLoad.Type.UpdateView;
                CurrentPayload               = payLoad;
                CurrentPayload.HasDataObject = true;
                CurrentPayload.DataObject    = clientDo;
                CurrentPayload.Subsystem     = payLoad.Subsystem;
            }
            else
            {
                string message = isInsert ? "Error during the insert" : "Error during the update";
                SendError(message);
            }
            return(payLoad);
        }