示例#1
0
        public T Insert(T entity)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(configManager.GetStringConnexion()))
                {
                    using (SqlCommand command = new SqlCommand())
                    {
                        var id = String.Empty;
                        command.Connection  = connection;
                        command.CommandType = CommandType.StoredProcedure;
                        command.CommandText = "insertonAlumnos";
                        foreach (var property in entity.GetType().GetProperties())
                        {
                            if (property.Name != "Id")
                            {
                                command.Parameters.AddWithValue(String.Concat("@", property.Name), property.GetValue(entity, null));
                            }
                        }
                        connection.Open();
                        command.ExecuteNonQuery();

                        return(SelectById((int)entity.GetType().GetProperty("Id").GetValue(entity)));
                    }
                }
            }
            catch (SqlException ex)
            {
                _log.Error(ex);
                throw;
            }
        }
示例#2
0
        public T Insert(T entity)
        {
            try
            {
                using (SqlConnection _connection = new SqlConnection(configManager.GetStringConnexion()))
                {
                    //query.Append("INSERT INTO dbo.Alumnos (");
                    var strInsert = new StringBuilder();
                    var strValues = new StringBuilder();
                    strInsert.Append(" INSERT INTO dbo.Alumnos(");
                    strValues.Append(" VALUES (");
                    foreach (var property in entity.GetType().GetProperties())
                    {
                        if (property.Name != "Id")
                        {
                            strInsert.Append(property.Name);
                            strInsert.Append(!typeof(T).GetProperties().Last().Equals(property) ? "," : ")");
                            strValues.Append(String.Concat("@", property.Name));
                            strValues.Append(!typeof(T).GetProperties().Last().Equals(property) ? "," : ")");
                        }
                    }

                    strInsert.Append(strValues.ToString());

                    using (var cmd = new SqlCommand(strInsert.ToString(), _connection))
                    {
                        _connection.Open();
                        cmd.CommandType = CommandType.Text;
                        foreach (var property in entity.GetType().GetProperties())
                        {
                            if (property.Name != "Id")
                            {
                                cmd.Parameters.AddWithValue(String.Concat("@", property.Name), property.GetValue(entity, null));
                            }
                        }
                        cmd.ExecuteNonQuery();
                        _connection.Close();
                    }

                    return(SelectById((int)entity.GetType().GetProperty("Id").GetValue(entity)));
                }
            }
            catch (SqlException ex)
            {
                _log.Error(ex);
                throw;
            }
        }
示例#3
0
        public T Insert(T entity)
        {
            try
            {
                IDAO <T> daof = DAOFactory <T> .getFormat();

                daof.
                _log.Info("Inicio AlumnoDao  " + System.Reflection.MethodBase.GetCurrentMethod().Name + " Alumno ->" + entity.ToString());
                return(iDoc.Insert(entity));
            }
            catch (ArgumentNullException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (PathTooLongException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (DirectoryNotFoundException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (UnauthorizedAccessException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (NotSupportedException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (System.Security.SecurityException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (IOException ex)
            {
                _log.Fatal("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (Exception ex)
            {
                _log.Fatal("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            finally
            {
                _log.Info("Fin de AlumnoDao " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }
示例#4
0
        public T Insert(T entity)
        {
            try
            {
                _log.Info("Inicio JSON " + System.Reflection.MethodBase.GetCurrentMethod().Name);

                List <T> entityList = SelectAll();
                if (entityList == null)
                {
                    entityList = new List <T>();
                }

                using (StreamWriter file = new StreamWriter(@PATH))
                {
                    JsonSerializer serializer = new JsonSerializer
                    {
                        Formatting = Formatting.Indented
                    };
                    entityList.Add(entity);
                    serializer.Serialize(file, entityList);
                }

                return(Select(entity.Guid));
            }
            catch (ArgumentNullException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (PathTooLongException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (DirectoryNotFoundException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (UnauthorizedAccessException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (NotSupportedException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (SecurityException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (IOException ex)
            {
                _log.Fatal("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (Exception ex)
            {
                _log.Fatal("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            finally
            {
                _log.Info("Fin de JSON " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }
示例#5
0
 public void LoadDocument()
 {
     PATH = GetPath();
     try
     {
         lock (lockThis)
         {
             _log.Info("Inicio DocumentManager " + System.Reflection.MethodBase.GetCurrentMethod().Name);
             if (!File.Exists(PATH))
             {
                 File.CreateText(PATH);
             }
         }
     }
     catch (ArgumentNullException ex)
     {
         _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
         throw;
     }
     catch (PathTooLongException ex)
     {
         _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
         throw;
     }
     catch (DirectoryNotFoundException ex)
     {
         _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
         throw;
     }
     catch (UnauthorizedAccessException ex)
     {
         _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
         throw;
     }
     catch (NotSupportedException ex)
     {
         _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
         throw;
     }
     catch (SecurityException ex)
     {
         _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
         throw;
     }
     catch (IOException ex)
     {
         _log.Fatal("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
         throw;
     }
     catch (Exception ex)
     {
         _log.Fatal("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
         throw;
     }
     finally
     {
         _log.Info("Fin de DocumentManager " + System.Reflection.MethodBase.GetCurrentMethod().Name);
     }
 }
示例#6
0
        public T Insert(T entity)
        {
            try
            {
                Log.Info("Inicio XML " + System.Reflection.MethodBase.GetCurrentMethod().Name);
                _log.Info("Inicio XML " + System.Reflection.MethodBase.GetCurrentMethod().Name);
                List <T>      entityList = SelectAll();
                XmlSerializer xSeriz     = new XmlSerializer(typeof(List <Alumno>));

                if (entityList == null)
                {
                    entityList = new List <T>();
                }

                using (FileStream fs1 = new FileStream(docManager.GetPath(), FileMode.Create))
                {
                    entityList.Add(entity);
                    xSeriz.Serialize(fs1, entityList);
                }

                return(Select(entity.Guid));
            }
            catch (ArgumentNullException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (PathTooLongException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (DirectoryNotFoundException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (UnauthorizedAccessException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (NotSupportedException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (SecurityException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (IOException ex)
            {
                _log.Fatal("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (Exception ex)
            {
                _log.Fatal("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            finally
            {
                _log.Info("Fin de XML " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }
示例#7
0
        public Alumno Add(Alumno alumno)
        {
            try
            {
                _log.Fatal("Inicio AlumnoBl " + System.Reflection.MethodBase.GetCurrentMethod().Name + " -> " + alumno.ToString());
                //Calcular Campos
                alumno.Edad          = CalcularEdad(alumno.FechaNacimiento);
                alumno.FechaRegistro = CalcularFechaRegistro();
                IDAO <Alumno> doc = DAOFactory <Alumno> .getFormat();

                return(doc.Insert(alumno));
            }
            catch (ArgumentNullException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (PathTooLongException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (DirectoryNotFoundException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (UnauthorizedAccessException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (NotSupportedException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (SecurityException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (IOException ex)
            {
                _log.Fatal("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (Exception ex)
            {
                _log.Fatal("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            finally
            {
                _log.Info("Fin de AlumnoBl " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }
示例#8
0
        public T Insert(T entity)
        {
            try
            {

                _log.Info("Inicio TXT " + System.Reflection.MethodBase.GetCurrentMethod().Name);
                using (var tw = new StreamWriter(DocumentsManager.PATH, true))
                {
                    tw.WriteLine(entity.ToString());
                }
                //throw new IOException();
                return Select(entity.Guid);
            }
            catch (ArgumentNullException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (PathTooLongException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (DirectoryNotFoundException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (UnauthorizedAccessException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (NotSupportedException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (SecurityException ex)
            {
                _log.Error("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (IOException ex)
            {
                _log.Fatal("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            catch (Exception ex)
            {
                _log.Fatal("Error en " + System.Reflection.MethodBase.GetCurrentMethod().Name + "--> " + ex.Message);
                throw;
            }
            finally
            {
                _log.Info("Fin de TXT " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }