public Tuple <bool, string[]> ActualizarBase(short empresaId, int ejercicio, int versionProcesarID, string idTemporal)
        {
            bool          todoCorrecto = false;
            List <string> errores      = new List <string>();

            try
            {
                FTPresupuestoEntities _contextDB = _dbContextCreator() as FTPresupuestoEntities;
                //_contextDB.Database.BeginTransaction();
                _contextDB.Database.CommandTimeout = 0;
                _contextDB.ActualizarBase_Ppto_Fert(0, empresaId, ejercicio, versionProcesarID, idTemporal);
                todoCorrecto = true;
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    errores.Add(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:"
                                              , eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        errores.Add(string.Format("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\""
                                                  , ve.PropertyName, eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName), ve.ErrorMessage));
                    }
                }
            }
            catch (Exception ex)
            {
                errores.Add(ex.Message);
                Exception _ex = ex.InnerException;
                while (_ex != null)
                {
                    errores.Add(_ex.Message);
                    _ex = _ex.InnerException;
                }
            }
            return(Tuple.Create(todoCorrecto, errores.ToArray()));
        }
        public async Task <Tuple <bool, string[]> > ActualizarBaseAsync(NuevaBaseEjercicioModel model, string[] selectedItems, string userName)
        {
            bool          todoCorrecto = false;
            List <string> errores      = new List <string>();

            try
            {
                //var userName = System.Web.HttpContext.Current.User.Identity.Name;
                FTPresupuestoEntities _contextDB = _dbContextCreator() as FTPresupuestoEntities;
                _contextDB.Database.CommandTimeout = 0;
                //_contextDB.Database.BeginTransaction();
                // SE CREA LA TABLA TEMPORAL Y SE ACUMULAN
                var resultaCrear = await ValidaExistenciaTemporalAsync();

                if (!resultaCrear.Item1)
                {
                    throw new Exception(string.Join(Environment.NewLine, resultaCrear.Item2));
                }
                string idTemporal = Guid.NewGuid().ToString();
                foreach (string selected in selectedItems)
                {
                    short pEjercicio = 0;
                    short.TryParse(selected.Substring(0, 4), out pEjercicio);
                    short pMes = 0;
                    short.TryParse(selected.Substring(4, 2), out pMes);
                    short pEmpresa = 0;
                    short.TryParse(selected.Substring(6, 2), out pEmpresa);
                    var resultaTmp = AgregarEnTemporal((short)model.Ejercicio, pEjercicio, pEmpresa, pMes, idTemporal);
                    if (!resultaTmp.Item1)
                    {
                        throw new Exception(string.Join(Environment.NewLine, resultaTmp.Item2));
                    }
                }
                // SE CREA NUEVA VERSION DE PRESUPUESTO
                int versionPptoID = model.VersionId;
                if (model.VersionId == 0)
                {
                    VersionPresupuesto versionPpto = new VersionPresupuesto
                    {
                        Consecutivo     = model.Consecutivo,
                        Ejercicio       = model.Ejercicio,
                        FechaCreacion   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day),
                        Observaciones   = model.Observaciones,
                        TipoPresupuesto = (int)enumTipoDePresupuesto.FERTILIZANTES,
                        UsuarioCreacion = userName,
                        EstaCerrado     = false
                    };
                    IVersionPresupuestoRepository verPptpRepo = new VersionPresupuestoRepository(_dbContextCreator);
                    var result = verPptpRepo.Create(versionPpto);
                    if (!result.Item1)
                    {
                        throw new Exception(string.Join(Environment.NewLine, result.Item2));
                    }
                    versionPptoID = versionPpto.VersionPresupuestoId;
                }
                // PROCESO PARA COPIAR VERSION DE PRESUPUESTO A NUEVA VERSION
                _contextDB.GenVersion_Ppto_Fertilizantes(model.VersionId, true, model.Observaciones, userName, model.Ejercicio, model.Consecutivo);
                //var resultNuevaVersion = GenerarVersion(model.VersionId, true, model.Observaciones, model.Ejercicio, model.Consecutivo, userName);
                //if (!resultNuevaVersion.Item1)
                //{
                //    throw new Exception(string.Join(Environment.NewLine, resultNuevaVersion.Item2));
                //}

                int versionProcesarID = FTPresupuestoProvider.getVersionPresupuestoIdByTipo(enumTipoDePresupuesto.FERTILIZANTES);

                _contextDB.ActualizarBase_Ppto_Fert(0, model.EmpresaId, model.Ejercicio, versionProcesarID, idTemporal);
                todoCorrecto = true;
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    errores.Add(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:"
                                              , eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        errores.Add(string.Format("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\""
                                                  , ve.PropertyName, eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName), ve.ErrorMessage));
                    }
                }
            }
            catch (Exception ex)
            {
                errores.Add(ex.Message);
                Exception _ex = ex.InnerException;
                while (_ex != null)
                {
                    errores.Add(_ex.Message);
                    _ex = _ex.InnerException;
                }
            }
            return(Tuple.Create(todoCorrecto, errores.ToArray()));
        }