public LibroDTO Insert(LibroDTO libroDTO)
        {
            if (string.IsNullOrEmpty(libroDTO.Titulo) || string.IsNullOrWhiteSpace(libroDTO.Titulo) ||
                string.IsNullOrEmpty(libroDTO.Libro_Autor.ToString()) || string.IsNullOrWhiteSpace(libroDTO.Libro_Autor.ToString()) ||
                string.IsNullOrEmpty(libroDTO.Libro_Editorial.ToString()) || string.IsNullOrWhiteSpace(libroDTO.Libro_Editorial.ToString()) ||
                string.IsNullOrEmpty(libroDTO.Genero) || string.IsNullOrWhiteSpace(libroDTO.Genero) ||
                string.IsNullOrEmpty(libroDTO.Año.ToString()) || string.IsNullOrWhiteSpace(libroDTO.Año.ToString()))
            {
                throw new ApplicationException("Datos incompletos");
            }



            Tb_Libro libro = Map(libroDTO);

            _context.Add(libro);
            if (_context.SaveChanges() >= 1)
            {
                return(Map(libro));
            }
            else
            {
                return(null);
            }
        }
        public EditorialDTO Insert(EditorialDTO editorialViewModel)
        {
            if (string.IsNullOrEmpty(editorialViewModel.Nombre) || string.IsNullOrWhiteSpace(editorialViewModel.Nombre) ||
                string.IsNullOrEmpty(editorialViewModel.Direccion) || string.IsNullOrWhiteSpace(editorialViewModel.Direccion) ||
                string.IsNullOrEmpty(editorialViewModel.Email) || string.IsNullOrWhiteSpace(editorialViewModel.Email))
            {
                throw new ApplicationException("Datos incompletos");
            }


            if (_context.Tb_editoriales.Any(e => e.Editorial_nombre.ToUpper() == editorialViewModel.Nombre.ToUpper()))
            {
                string mensaje = string.Format("Ya existe la editorial {0}", editorialViewModel.Nombre);
                throw new ApplicationException(mensaje);
            }

            Tb_Editorial editorial = Map(editorialViewModel);

            _context.Add(editorial);
            if (_context.SaveChanges() >= 1)
            {
                return(Map(editorial));
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        /// <summary>
        /// Inserta Autores
        /// </summary>
        /// <param name="autorlViewModel"></param>
        /// <returns></returns>
        public AutorDTO Insert(AutorDTO autorlViewModel)
        {
            if (String.IsNullOrEmpty(autorlViewModel.Nombre) || String.IsNullOrWhiteSpace(autorlViewModel.Nombre) ||
                String.IsNullOrEmpty(autorlViewModel.Ciudad) || String.IsNullOrWhiteSpace(autorlViewModel.Ciudad) ||
                String.IsNullOrEmpty(autorlViewModel.FechaNacimiento.ToString()) || String.IsNullOrWhiteSpace(autorlViewModel.FechaNacimiento.ToString()) ||
                String.IsNullOrEmpty(autorlViewModel.Email) || String.IsNullOrWhiteSpace(autorlViewModel.Email))
            {
                throw new ApplicationException("Datos Incompletos");
            }

            Tb_Autor autor = Map(autorlViewModel);

            _context.Add(autor);
            if (_context.SaveChanges() >= 1)
            {
                return(Map(autor));
            }
            else
            {
                return(null);
            }
        }