public async Task Should_Create_AgentCorrectly() { string numComi = _commissionAgentDataServices.NewId(); var commissionAgent = _commissionAgentDataServices.GetNewDo(numComi); var ret = _commissionAgentDataServices.SaveAsync(commissionAgent); commissionAgent = await _commissionAgentDataServices.GetDoAsync(numComi); Assert.NotNull(commissionAgent); var value = commissionAgent.Value as ComisioViewObject; Assert.NotNull(value); Assert.AreEqual(value.NUM_COMI, numComi); }
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); }