예제 #1
0
        public ActionResult Create(tesis tesis, HttpPostedFileBase ffile, List <string> GrupoAcademico)
        {
            archivo file = null;

            if (!ModelState.IsValid)
            {
                ViewBag.grupo   = db.grupoacademico.ToList();
                ViewBag.autores = db.usuario.Where(x => x.Status.Equals("A")).ToList();
                return(View(tesis));
            }
            try
            {
                string dir      = "~/Content/Archivos/Capitulos";
                string fileName = "";
                string path     = "";
                if (!Directory.Exists(dir))
                {
                    DirectoryInfo di = Directory.CreateDirectory(Server.MapPath(dir));
                }
                if (ffile != null && ffile.ContentLength > 0)
                {
                    fileName = Path.GetFileName(ffile.FileName);
                    path     = Path.Combine(Server.MapPath(dir), DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + fileName);
                    ffile.SaveAs(path);
                    file        = new archivo();
                    file.Nombre = fileName;
                    file.url    = path;
                    db.archivo.Add(file);
                    db.SaveChanges();
                }

                if (file != null)
                {
                    tesis.archivo = file.idarchivo;
                }
                tesis.usuario = int.Parse(Session["id"].ToString().ToString());
                db.tesis.Add(tesis);
                db.SaveChanges();
                if (GrupoAcademico != null)
                {
                    foreach (var s in GrupoAcademico)
                    {
                        tesis_grupo ag = new tesis_grupo
                        {
                            idtesis = tesis.idtesis,
                            idgrupo = int.Parse(s)
                        };
                        db.tesis_grupo.Add(ag);
                    }
                }
                db.SaveChanges();
                return(RedirectToAction("Index", new { response = 1 }));
            }
            catch (Exception e)
            {
                return(Content(e + ""));
            }
        }
예제 #2
0
        public ActionResult Search(string Nombre, string autor, DateTime?Y1, DateTime?Y2, List <string> grupos, string asesor)
        {
            ViewBag.grupos  = db.grupoacademico.ToList();
            ViewBag.autores = db.usuario.Where(x => x.Status.Equals("A")).ToList();
            List <tesis> tesis = db.tesis.ToList();

            if (Nombre != null)
            {
                tesis = tesis.Where(x => x.titulo.Contains(Nombre)).ToList();
            }
            if (Y1 != null)
            {
                //int year1 = int.Parse(Y1);
                tesis = tesis.Where(x => x.fecha >= Y1).ToList();
            }
            if (Y2 != null)
            {
                tesis = tesis.Where(x => x.fecha <= Y2).ToList();
            }
            if (grupos != null)
            {
                List <tesis> cg = new List <tesis>();
                foreach (string s in grupos)
                {
                    int i = int.Parse(s);
                    var g = db.tesis_grupo.Where(x => x.idgrupo == i).ToList();

                    foreach (var cap in g)
                    {
                        tesis sample = db.tesis.Where(x => x.idtesis == cap.idtesis).FirstOrDefault();
                        cg.Add(sample);
                    }
                }
                tesis = tesis.Where(x => cg.Contains(x)).ToList();
            }
            if (!String.IsNullOrEmpty(autor))
            {
                tesis = tesis.Where(x => x.autor == int.Parse(autor)).ToList();
            }
            if (!String.IsNullOrEmpty(asesor))
            {
                tesis = tesis.Where(x => x.asesor == int.Parse(asesor)).ToList();
            }
            return(PartialView("_TesisPartial", tesis));
        }
예제 #3
0
 public ActionResult Edit(int id, tesis tesis, List <string> GrupoAcademico, HttpPostedFileBase ffile, string autor)
 {
     if (!ModelState.IsValid && (String.IsNullOrEmpty(autor) == false))
     {
         ViewBag.grupo   = db.grupoacademico.ToList();
         ViewBag.autores = db.usuario.Where(x => x.Status.Equals("A")).ToList();
         return(View(tesis));
     }
     try
     {
         var l = db.tesis.Where(x => x.idtesis == id).FirstOrDefault();
         l.titulo          = tesis.titulo;
         l.jurado          = tesis.jurado;
         l.asesor          = tesis.asesor;
         l.codirector      = tesis.codirector;
         l.director        = tesis.director;
         l.usuario2        = tesis.usuario2;
         l.autor           = int.Parse(autor);
         l.fecha           = tesis.fecha;
         l.Carrera         = tesis.Carrera;
         l.grado_academico = tesis.grado_academico;
         var grupos_eliminar = db.tesis_grupo.Where(x => x.idtesis == id).ToList();
         if (grupos_eliminar != null)
         {
             foreach (var G in grupos_eliminar)
             {
                 db.tesis_grupo.Remove(G);
             }
         }
         if (GrupoAcademico != null)
         {
             foreach (var G in GrupoAcademico)
             {
                 db.tesis_grupo.Add(new tesis_grupo {
                     idtesis = id, idgrupo = int.Parse(G)
                 });
             }
         }
         if (ffile != null && ffile.ContentLength > 0)
         {
             if (l.archivo1 != null)
             {
                 var archivo = new archivo();
                 archivo = db.archivo.Where(x => x.idarchivo == l.archivo).FirstOrDefault();
                 System.IO.File.Delete(l.archivo1.url);
                 db.archivo.Remove(archivo);
             }
             string dir = "~/Content/Archivos/Capitulos";
             if (!Directory.Exists(dir))
             {
                 DirectoryInfo di = Directory.CreateDirectory(Server.MapPath(dir));
             }
             string fileName = Path.GetFileName(ffile.FileName);
             string path     = Path.Combine(Server.MapPath(dir), DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + fileName);
             ffile.SaveAs(path);
             archivo file = new archivo();
             file.Nombre = fileName;
             file.url    = path;
             db.archivo.Add(file);
             db.SaveChanges();
             l.archivo = file.idarchivo;
         }
         db.SaveChanges();
         return(RedirectToAction("Index", new { response = 1 }));
     }
     catch (Exception e)
     {
         return(RedirectToAction("Index", new { response = 2 }));
     }
 }