Example #1
0
        /// <summary>
        ///  Parse the result of an office multiple query
        /// </summary>
        /// <param name="request"></param>
        /// <param name="reader"></param>
        /// <returns></returns>

        private bool ParseResult(OfficeViewObject request, OFICINAS value, SqlMapper.GridReader reader)
        {
            if ((request == null) || (reader == null))
            {
                return(false);
            }
            if (request.Value == null)
            {
                return(false);
            }
            try
            {
                request.City           = SelectionHelpers.WrappedSelectedDto <POBLACIONES, CityViewObject>(value.CP, _mapper, reader);
                request.Province       = SelectionHelpers.WrappedSelectedDto <PROVINCIA, ProvinceViewObject>(value.PROVINCIA, _mapper, reader);
                request.Currencies     = SelectionHelpers.WrappedSelectedDto <CURRENCIES, CurrenciesViewObject>(value.CURRENCY_OFI, _mapper, reader);
                request.HolidayDates   = SelectionHelpers.WrappedSelectedDto <FESTIVOS_OFICINA, HolidayViewObject>(value.CODIGO, _mapper, reader);
                request.DelegaContable = SelectionHelpers.WrappedSelectedDto <DELEGA, DelegaContableViewObject>(value.DEPARTA, _mapper, reader);
                request.Country        = SelectionHelpers.WrappedSelectedDto <Country, CountryViewObject>(value.PAIS, _mapper, reader);
                request.OfficeZone     = SelectionHelpers.WrappedSelectedDto <ZONAOFI, ZonaOfiViewObject>(value.ZONAOFI, _mapper, reader);
#pragma warning disable CS0168 // Variable is declared but never used
            }
            catch (System.Exception ex)
#pragma warning restore CS0168 // Variable is declared but never used
            {
                return(false);
            }
            return(true);
        }
Example #2
0
        private IQueryStore CreateQueryStore(OFICINAS office)
        {
            IQueryStore store = _queryStoreFactory.GetQueryStore();

            store.AddParam(QueryType.QueryCity, office.CP);
            store.AddParam(QueryType.QueryOfficeZone, office.ZONAOFI);
            return(store);
        }
Example #3
0
        /// <summary>
        ///  This saves the holiday in the office.
        /// </summary>
        /// <param name="currentOffice">Current office to be saved.</param>
        /// <param name="holidayDto">List of vacation for the current office.</param>
        /// <returns>return a task for saving the holidays</returns>
        private async Task <bool> SaveHolidayOfficeAsync(IDbConnection connection, OFICINAS currentOffice, IEnumerable <HolidayDto> holidayDto)
        {
            Contract.Requires(connection != null, "Connection is not null");
            Contract.Requires(currentOffice != null, "Current office is not null");
            Contract.Requires(holidayDto != null, "HolidayDto is not null");
            if (currentOffice.CODIGO == null)
            {
                throw new ArgumentNullException("Office code is null");
            }

            if (holidayDto.Count() == 0)
            {
                return(true);
            }

            IEnumerable <FESTIVOS_OFICINA> holidayOffice = _mapper.Map <IEnumerable <HolidayDto>, IEnumerable <FESTIVOS_OFICINA> >(holidayDto);
            IQueryStore store = _queryStoreFactory.GetQueryStore();

            store.AddParam(QueryType.HolidaysByOffice, currentOffice.CODIGO);
            var  query = store.BuildQuery();
            bool saved = false;

            // First i want fetch the current festivo oficina.
            // we shall insert or merge.
            try
            {
                var currentHolidays = await connection.QueryAsync <FESTIVOS_OFICINA>(query);

                var festivosOficinas = currentHolidays as FESTIVOS_OFICINA[] ?? currentHolidays.ToArray();
                if (!festivosOficinas.Any())
                {
                    saved = await connection.InsertAsync(holidayOffice).ConfigureAwait(false) > 0;
                }
                else
                {
                    // divide what to be inserted from what we should update.
                    var holidayValues = DistintSelect(currentHolidays, holidayOffice);
                    var value         = holidayValues.Item2.ToList();
                    if (holidayValues.Item2.Any())
                    {
                        saved = await connection.InsertAsync(holidayValues.Item2).ConfigureAwait(false) > 0;
                    }
                    if (holidayValues.Item1.Any())
                    {
                        saved = saved && await connection.UpdateAsync(holidayValues.Item1).ConfigureAwait(false);
                    }
                }
            }
            catch (System.Exception e)
            {
                connection.Close();
                connection.Dispose();
                throw new DataLayerException(e.Message, e);
            }
            return(saved);
        }
Example #4
0
        /// <summary>
        ///  Get an unique id for the office table. The id is a new identifier that it can be used for inserting
        ///  a new office in the database
        /// </summary>
        /// <returns>Return a new identifier</returns>
        public string GetNewId()
        {
            var oficinas = new OFICINAS();
            var id       = string.Empty;

            using (var conn = SqlExecutor.OpenNewDbConnection())
            {
                id = conn.UniqueId <OFICINAS>(oficinas);
            }
            return(id);
        }
Example #5
0
        /// <summary>
        ///  Get an unique id for the office table. The id is a new identifier that it can be used for inserting
        ///  a new office in the database
        /// </summary>
        /// <returns>Return a new identifier</returns>
        public string GetNewId()
        {
            OFICINAS oficinas = new OFICINAS();
            string   id       = string.Empty;

            using (IDbConnection conn = _sqlExecutor.OpenNewDbConnection())
            {
                id = conn.UniqueId <OFICINAS>(oficinas);
            }
            return(id);
        }
Example #6
0
        protected void ddlCorresponsales_SelectedIndexChanged(object sender, EventArgs e)
        {
            lblCorresponsal.Text = "";
            lblOficina.Text      = "";

            OFICINAS of = client.OFICINAS(Convert.ToInt32(ddlCorresponsales.SelectedItem.Value)).FirstOrDefault();

            Resultado(of.OFI_NOMBRE);

            lblCorresponsal.Text = $"Corresponsal: {ddlCorresponsales.SelectedItem.Text}";
            lblOficina.Text      = $"Oficina: {of.OFI_NOMBRE}";
        }
Example #7
0
        /// <summary>
        ///  This saves the holiday in the office.
        /// </summary>
        /// <param name="currentOffice">Current office to be saved.</param>
        /// <param name="holidayDto">List of vacation for the current office.</param>
        /// <returns>return a task for saving the holidays</returns>
        private async Task SaveHolidayOfficeAsync(IDbConnection connection, OFICINAS currentOffice, IEnumerable <HolidayDto> holidayDto)
        {
            Contract.Requires(connection != null, "Connection is not null");
            Contract.Requires(currentOffice != null, "Current office is not null");
            Contract.Requires(holidayDto != null, "HolidayDto is not null");

            IEnumerable <FESTIVOS_OFICINA> holidayOffice = _mapper.Map <IEnumerable <HolidayDto>, IEnumerable <FESTIVOS_OFICINA> >(holidayDto);
            IQueryStore store = _queryStoreFactory.GetQueryStore();

            store.AddParam(QueryType.HolidaysByOffice, currentOffice.CODIGO);
            var  query = store.BuildQuery();
            bool saved = false;

            // First i want fetch the current festivo oficina.
            // we shall insert or merge.
            try
            {
                IEnumerable <FESTIVOS_OFICINA> currentHolidays = await connection.QueryAsync <FESTIVOS_OFICINA>(query);

                if (currentHolidays.Count <FESTIVOS_OFICINA>() == 0)
                {
                    connection.BulkInsert(holidayOffice);
                }
                else
                {
                    // FIXME : check for concurrent optimistic lock.
                    var holidaysToBeInserted = holidayOffice.Except(currentHolidays);
                    connection.BulkInsert <FESTIVOS_OFICINA>(holidaysToBeInserted);
                    var holidaysToBeUpdated = holidayOffice.Intersect(currentHolidays);
                    connection.BulkUpdate <FESTIVOS_OFICINA>(holidaysToBeUpdated);
                }
                saved = true;
            }
            catch (System.Exception e)
            {
                connection.Close();
                connection.Dispose();
                throw new DataLayerException(e.Message, e);
            }
            Contract.Ensures(saved);
        }
Example #8
0
        private async Task <OfficeDtos> LoadAuxAsync(IDbConnection connection,
                                                     OfficeDtos officeDtos, OFICINAS value)

        {
            if ((officeDtos == null) || (value == null) || (connection == null))
            {
                throw new ArgumentNullException("Invalid input during load!");
            }
            var auxQueryStore = _queryStoreFactory.GetQueryStore();

            auxQueryStore.AddParamCount(QueryType.QueryCity, value.CP);
            auxQueryStore.AddParamCount(QueryType.QueryProvince, value.PROVINCIA);
            auxQueryStore.AddParamCount(QueryType.QueryCurrencyValue, value.CURRENCY_OFI);
            auxQueryStore.AddParamCount(QueryType.HolidaysByOffice, value.CODIGO);
            auxQueryStore.AddParamCount(QueryType.QueryDeptContable, value.DEPARTA);
            auxQueryStore.AddParamCount(QueryType.QueryCountry, value.PAIS);
            auxQueryStore.AddParamCount(QueryType.QueryOfficeZone, value.ZONAOFI);
            var query          = auxQueryStore.BuildQuery();
            var multipleResult = await connection.QueryMultipleAsync(query).ConfigureAwait(false);

            officeDtos.IsValid = ParseResult(officeDtos, value, multipleResult);
            return(officeDtos);
        }