public async Task Should_Load_And_Have_TheSame_NumComi() { IDictionary <string, string> query = new Dictionary <string, string>(); string primaryKeyValue = await GetFirstId(); using (IDbConnection connection = _sqlExecutor.OpenNewDbConnection()) { var brokers = await connection.GetPagedAsync <COMISIO>(1, 20); var singleBroker = brokers.FirstOrDefault(); if (singleBroker != null) { primaryKeyValue = singleBroker.NUM_COMI; } } query["COMISIO"] = "NUM_COMI,PERSONA,NIF,TIPOCOMI,VENDE_COMI,MERCADO,NEGOCIO,CANAL,CLAVEPPTO,ORIGEN_COMI,ZONAOFI," + "direccion,cp,poblacion,provincia,nacioper,telefono,fax,Movil,alta_comi," + "baja_comi,idioma,IATA,IVASINO,RETENSINO,NACIONAL,CONCEPTOS_COND,AGENCIA,TRADUCE_WS," + "TRUCK_RENTAL_BROKER,COMBUS_PREPAGO_COMI,NO_GENERAR_AUTOFAC,TODOS_EXTRAS,AUTO_ONEWAY,COT_INCLUIDOS_SIN_GRUPO," + "NO_MAIL_RES,AUTOFAC_SIN_IVA,COMISION_SIN_IVA_COM"; ICommissionAgent agent = await _commissionAgentDataServices.GetCommissionAgentDo(primaryKeyValue, query); Assert.NotNull(agent); Assert.NotNull(agent.Value); ComisioViewObject comisio = (ComisioViewObject)agent.Value; Assert.NotNull(comisio.NUM_COMI, primaryKeyValue); }
/// <summary> /// Create a domain wrapper for the commission agent transfer object /// </summary> /// <param name="viewObject">Data Transfer Object.</param> /// <returns></returns> public virtual async Task <ICommissionAgent> CreateCommissionAgentAsync(ComisioViewObject viewObject) { ICommissionAgent data = await _services.GetCommissionAgentDataServices().GetCommissionAgentDo(viewObject.NUM_COMI); data.Value = viewObject; return(data); }
public async Task Should_LoopAndLoad_CommissionAgent() { // arrange IDictionary <string, string> fields = new Dictionary <string, string>(); string numComi = ""; using (IDbConnection connection = _sqlExecutor.OpenNewDbConnection()) { var allComisio = connection.GetAll <COMISIO>(); var defaultComi = allComisio.FirstOrDefault(); numComi = defaultComi.NUM_COMI; } fields.Add(CommissionAgent.Comisio, "COMISIO, NUM_COMI, PERSONA, NIF, TIPOCOMI, " + "VENDE_COMI, MERCADO, NEGOCIO, CANAL, CLAVEPPTO, " + "ORIGEN_COMI, ZONAOFI, direccion, cp, poblacion, " + "provincia, nacioper, telefono, fax, " + "Movil, alta_comi, baja_comi, idioma, IATA, IVASINO, " + "RETENSINO, NACIONAL, CONCEPTOS_COND, AGENCIA, TRADUCE_WS, " + "TRUCK_RENTAL_BROKER, COMBUS_PREPAGO_COMI, NO_GENERAR_AUTOFAC, " + "TODOS_EXTRAS, NO_GESTIONAR_CUPO, AUTO_ONEWAY, COT_INCLUIDOS_SIN_GRUPO, " + "ACCESO_PREMIUM, NO_MAIL_RES, AUTOFAC_SIN_IVA, " + "COMISION_SIN_IVA_COM"); for (int i = 0; i < 10; ++i) { // act ICommissionAgent agentDataWrapper = await _commissionAgentDataServices.GetCommissionAgentDo(numComi, fields); // assert. Assert.NotNull(agentDataWrapper); Assert.AreEqual(numComi, agentDataWrapper.Value.NUM_COMI); } }
/// <summary> /// New commission agent /// </summary> /// <returns>Returns the commission agent.</returns> public ICommissionAgent GetNewCommissionAgentDo(string id) { CommissionAgentFactory factory = CommissionAgentFactory.GetFactory(_sqlExecutor); ICommissionAgent agent = factory.NewCommissionAgent(id); return(agent); }
/// <summary> /// Create a domain wrapper for the commission agent transfer object /// </summary> /// <param name="dto">Data Transfer Object.</param> /// <returns></returns> public virtual async Task <ICommissionAgent> CreateCommissionAgentAsync(ComisioDto dto) { ICommissionAgent data = await _services.GetCommissionAgentDataServices().GetCommissionAgentDo(dto.NUM_COMI); data.Value = dto; return(data); }
public async Task Should_Update_CommissionAgent() { // arrange IDictionary <string, string> fields = new Dictionary <string, string>(); fields.Add(CommissionAgent.Comisio, "NUM_COMI,NOMBRE,DIRECCION,PERSONA,NIF,NACIOPER,TIPOCOMI"); fields.Add(CommissionAgent.Tipocomi, "NUM_TICOMI, ULTMODI, USUARIO, NOMBRE"); fields.Add(CommissionAgent.Visitas, " * "); fields.Add(CommissionAgent.Branches, "* "); string numComi = await GetFirstId(); ICommissionAgent commissionAgent = await _commissionAgentDataServices.GetCommissionAgentDo(numComi).ConfigureAwait(false); // check if the condition is valid. Assert.True(commissionAgent.Valid); ComisioViewObject internalValue = (ComisioViewObject)commissionAgent.Value; IEnumerable <BranchesViewObject> branchesDto = commissionAgent.BranchesDto; IEnumerable <ContactsViewObject> contactsDtos = commissionAgent.ContactsDto; IEnumerable <VisitsViewObject> visitsDtos = commissionAgent.VisitsDto; internalValue.NOMBRE = "Karve2Comission"; commissionAgent.Value = internalValue; // act bool isSaved = await _commissionAgentDataServices.SaveAsync(commissionAgent).ConfigureAwait(false); // assert Assert.True(isSaved); }
/// <summary> /// New commission agent /// </summary> /// <returns>Returns the commission agent.</returns> public ICommissionAgent GetNewCommissionAgentDo() { CommissionAgentFactory factory = CommissionAgentFactory.GetFactory(_sqlExecutor); string id = GetNewId(); logger.Debug("GetCommissionAgent " + id); ICommissionAgent agent = factory.NewCommissionAgent(id); return(agent); }
public async Task Should_DeleteCommissionAgent_ById() { IDictionary <string, string> fields = new Dictionary <string, string>(); fields.Add(CommissionAgent.Comisio, "NUM_COMI,NOMBRE,DIRECCION,PERSONA,NIF,NACIOPER,TIPOCOMI"); fields.Add(CommissionAgent.Tipocomi, "NUM_TICOMI, ULTMODI, USUARIO, NOMBRE"); fields.Add(CommissionAgent.Visitas, " * "); fields.Add(CommissionAgent.Branches, " * "); string numComi = "0000003"; ICommissionAgent commissionAgent = await _commissionAgentDataServices.GetCommissionAgentDo(numComi, fields); bool deleteSuccess = await _commissionAgentDataServices.DeleteAsync(commissionAgent).ConfigureAwait(false); Assert.True(deleteSuccess); }
/// <summary> /// Initialization on property changed. /// </summary> /// <param name="sender">This is the sender.</param> /// <param name="e">Parameters</param> private void InitializationDataObjectOnPropertyChanged(object sender, PropertyChangedEventArgs e) { IsVisible = Visibility.Visible; if (sender is ICommissionAgent) { ICommissionAgent agent = (ICommissionAgent)sender; DataObject = agent; Province = agent.ProvinceDto; Country = agent.CountryDto; for (int i = 0; i < _leftSideDualDfSearchBoxes.Count; ++i) { _leftSideDualDfSearchBoxes[i].DataSource = agent; } _leftObservableCollection = _leftSideDualDfSearchBoxes; } }
/// <summary> /// This returns to us a commission agent object. /// </summary> /// <param name="queryDictionary">Dictionary of fields to be included in the query.</param> /// <param name="commissionAgentId">Agent id to be fetched</param> /// <returns>The commission agent list.</returns> public async Task <ICommissionAgent> GetCommissionAgentDo(string commissionAgentId, IDictionary <string, string> queryDictionary = null) { IDictionary <string, string> queries; logger.Debug("GetCommissionAgentData Object"); if (queryDictionary == null) { queries = base.baseQueryDictionary; } else { queries = queryDictionary; } CommissionAgentFactory agentFactory = CommissionAgentFactory.GetFactory(_sqlExecutor); ICommissionAgent createdAgent = await agentFactory.GetCommissionAgent(queries, commissionAgentId); return(createdAgent); }
/// <summary> /// Save commission agent. /// </summary> /// <param name="commissionAgent">Commission agent saved.</param> /// <returns>True when the commission agent has been deleted.</returns> public async Task <bool> DeleteCommissionAgent(ICommissionAgent commissionAgent) { bool value = false; IDbConnection connection = _sqlExecutor.Connection; using (connection) { if (connection.State != ConnectionState.Open) { connection.Open(); } value = await commissionAgent.DeleteAsyncData().ConfigureAwait(false); } if (!value) { logger.Debug("Failed to delete commission agent"); } return(value); }
/// <summary> /// This program loads the data from the data values. /// </summary> /// <param name="primaryKeyValue">Primary Key.</param> /// <param name="isInsertion">Inserted key.</param> /// <returns></returns> private async Task <ICommissionAgent> LoadDataValue(string primaryKeyValue, bool isInsertion) { ICommissionAgent agent = null; if (isInsertion) { agent = await _commissionAgentDataServices.GetDoAsync(_primaryKeyValue); if (agent != null) { DataObject = agent; } } else { agent = await _commissionAgentDataServices.GetCommissionAgentDo(primaryKeyValue).ConfigureAwait(false); } return(agent); }
public async Task Should_Load_Commission_Agent_ByFactory() { IDictionary <string, string> fields = new Dictionary <string, string>(); string numComi = "0000002"; fields.Add(CommissionAgent.Comisio, "COMISIO, NUM_COMI, PERSONA, NIF, TIPOCOMI, " + "VENDE_COMI, MERCADO, NEGOCIO, CANAL, CLAVEPPTO, " + "ORIGEN_COMI, ZONAOFI, direccion, cp, poblacion, " + "provincia, nacioper, telefono, fax, " + "Movil, alta_comi, baja_comi, idioma, IATA, IVASINO, " + "RETENSINO, NACIONAL, CONCEPTOS_COND, AGENCIA, TRADUCE_WS, " + "TRUCK_RENTAL_BROKER, COMBUS_PREPAGO_COMI, NO_GENERAR_AUTOFAC, " + "TODOS_EXTRAS, NO_GESTIONAR_CUPO, AUTO_ONEWAY, COT_INCLUIDOS_SIN_GRUPO, " + "ACCESO_PREMIUM, NO_MAIL_RES, AUTOFAC_SIN_IVA, " + "COMISION_SIN_IVA_COM"); CommissionAgentFactory agentFactory = CommissionAgentFactory.GetFactory(_sqlExecutor); Assert.NotNull(agentFactory); ICommissionAgent createdAgent = await agentFactory.GetCommissionAgent(fields, numComi); Assert.NotNull(createdAgent); }
/// <summary> /// Delete a commission agent. /// </summary> /// <param name="inDataPayLoad"></param> /// <returns></returns> private async Task <DataPayLoad> HandleDeleteItem(DataPayLoad inDataPayLoad) { ICommissionAgent agent = await _commissionAgentDataServices.GetCommissionAgentDo(inDataPayLoad.PrimaryKeyValue); DataPayLoad payload = new DataPayLoad(); if (agent.Valid) { bool returnValue = await _commissionAgentDataServices.DeleteAsync(agent); if (returnValue) { payload.Subsystem = DataSubSystem.CommissionAgentSubystem; payload.PrimaryKeyValue = inDataPayLoad.PrimaryKeyValue; payload.PayloadType = DataPayLoad.Type.Delete; EventManager.NotifyToolBar(payload); _primaryKeyValue = ""; _commissionAgentDo = null; } } return(payload); }
/// <summary> /// Save commission agent /// </summary> /// <param name="commissionAgent">Commission Agent to be saved.</param> /// <returns>Returns true if the commission agent has been changed.</returns> public async Task <bool> SaveAsync(ICommissionAgent commissionAgent) { var isPresent = false; using (var connection = _sqlExecutor.OpenNewDbConnection()) { var dto = commissionAgent.Value; var value = await connection.GetAsync <COMISIO>(dto.NUM_COMI).ConfigureAwait(false); isPresent = (value != null); } var changedTask = false; if (!isPresent) { changedTask = await commissionAgent.Save().ConfigureAwait(false); } else { changedTask = await commissionAgent.SaveChanges().ConfigureAwait(false); } return(changedTask); }
public override async Task <ICommissionAgent> CreateCommissionAgentAsync(ComisioViewObject viewObject) { ICommissionAgent agent = await _services.GetCommissionAgentDataServices().GetCommissionAgentDo(viewObject.NUM_COMI).ConfigureAwait(false); return(agent); }
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); }
public Task <bool> DeleteAsync(ICommissionAgent booking) { throw new System.NotImplementedException(); }
/// <summary> /// Save commission agent /// </summary> /// <param name="commissionAgent">Commission Agent to be saved.</param> /// <returns>Returns true if the commission agent has been changed.</returns> public async Task <bool> SaveCommissionAgent(ICommissionAgent commissionAgent) { bool changedTask = await commissionAgent.Save().ConfigureAwait(false); return(changedTask); }
public async Task Should_InsertContacts_Correctly() { // arrange IDictionary <string, string> fields; fields = new Dictionary <string, string> { { CommissionAgent.Comisio, "NUM_COMI,NOMBRE,DIRECCION,PERSONA,NIF,NACIOPER,TIPOCOMI" }, { CommissionAgent.Tipocomi, "NUM_TICOMI, ULTMODI, USUARIO, NOMBRE" }, { CommissionAgent.Visitas, " * " }, { CommissionAgent.Branches, "* " } }; string numComi = await GetFirstId(); ICommissionAgent commissionAgent = await _commissionAgentDataServices.GetCommissionAgentDo(numComi); // check if the condition is valid. Assert.True(commissionAgent.Valid); ComisioViewObject internalValue = (ComisioViewObject)commissionAgent.Value; ContactsViewObject contactsViewObject = new ContactsViewObject(); string contactosId = string.Empty; int comiDelega = 0; // this open a db connection and ensure that the primary key is unique. using (var dbconnection = _sqlExecutor.OpenNewDbConnection()) { CONTACTOS_COMI comi = new CONTACTOS_COMI(); contactosId = dbconnection.UniqueId(comi); var allDelega = await dbconnection.GetAsyncAll <COMI_DELEGA>(); var singleDelega = allDelega.FirstOrDefault(); if (singleDelega != null) { comiDelega = singleDelega.cldIdDelega; } } Random random = new Random(); contactsViewObject.ContactId = contactosId; contactsViewObject.ContactName = "Pineapple"; contactsViewObject.ContactsKeyId = internalValue.NUM_COMI; contactsViewObject.Nif = "Y171559F"; contactsViewObject.Email = "*****@*****.**"; contactsViewObject.Movil = "33409304"; contactsViewObject.State = 0; contactsViewObject.ResponsabilitySource = new PersonalPositionViewObject(); contactsViewObject.ResponsabilitySource.Code = "1"; contactsViewObject.ResponsabilitySource.Name = "GERENTE"; contactsViewObject.CurrentDelegation = comiDelega.ToString(); contactsViewObject.IsDirty = true; contactsViewObject.IsNew = true; IHelperDataServices helper = _dataServices.GetHelperDataServices(); IList <ContactsViewObject> entities = new List <ContactsViewObject>(); entities.Add(contactsViewObject); // act bool inserted = await helper.ExecuteBulkInsertAsync <ContactsViewObject, CONTACTOS_COMI>(entities); var allSavedContacts = await helper.GetMappedAllAsyncHelper <ContactsViewObject, CONTACTOS_COMI>(); var singleContact = allSavedContacts.FirstOrDefault(x => x.ContactId == contactosId); Assert.True(inserted); Assert.NotNull(singleContact); Assert.AreEqual(singleContact.ContactsKeyId, contactsViewObject.ContactsKeyId); Assert.AreEqual(singleContact.Email, contactsViewObject.Email); Assert.AreEqual(singleContact.Nif, contactsViewObject.Nif); Assert.AreEqual(singleContact.Movil, contactsViewObject.Movil); Assert.AreEqual(singleContact.State, contactsViewObject.State); Assert.AreEqual(singleContact.ResponsabilitySource.Code, contactsViewObject.ResponsabilitySource.Code); Assert.AreEqual(singleContact.ResponsabilitySource.Name, contactsViewObject.ResponsabilitySource.Name); }