public List <string> Obtener20UltimosAuncios(int condominio)
        {
            try
            {
                SigescoEntities bd            = new SigescoEntities();
                var             listaAnuncios = (from a in bd.ANUNCIOS
                                                 where a.ID_CONDOMINIO == condominio
                                                 orderby a.FECHA_ANUNCIO descending
                                                 select a).Take(20).ToList();

                List <string>   lista  = new List <string>();
                List <ANUNCIOS> _lista = listaAnuncios;
                int             x      = _lista.Count();
                for (int i = 0; i < x; i++)
                {
                    ANUNCIOS obj = new ANUNCIOS();
                    obj = _lista[i];
                    string fecha = Convert.ToDateTime(obj.FECHA_ANUNCIO).ToString("dddd dd, MMMM, yyyy");
                    string fila  = obj.TITULO + "|" + obj.CUERPO + "|" + obj.REMITENTE + "|" + fecha;
                    lista.Add(fila);
                }

                return(lista);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 public string ultimoAnuncio()
 {
     try
     {
         SigescoEntities bd        = new SigescoEntities();
         var             q_anuncio = from a in bd.ANUNCIOS orderby a.FECHA_ANUNCIO descending select a;
         ANUNCIOS        anun      = q_anuncio.First();
         string          ultimo    = anun.FECHA_ANUNCIO + "|" + anun.TITULO + "|" + anun.CUERPO + "|" + anun.REMITENTE;
         return(ultimo);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public bool CrearAnuncio(ANUNCIOS anun)
 {
     try
     {
         SigescoEntities bd = new SigescoEntities();
         using (bd)
         {
             var query = (from a in bd.ANUNCIOS
                          orderby a.ID_ANUNCIO descending
                          select a.ID_ANUNCIO).FirstOrDefault();
             anun.ID_ANUNCIO = query + 1;
             bd.ANUNCIOS.Add(anun);
             bd.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Example #4
0
        public JsonResult CrearAnuncios(FormCollection collection)
        {
            AnunciosDAL bd   = new AnunciosDAL();
            ANUNCIOS    anun = new ANUNCIOS();

            anun.ID_CONDOMINIO = int.Parse(collection["Condominio"].ToString());
            anun.TITULO        = collection["Titulo"].ToString();
            anun.CUERPO        = collection["Cuerpo"].ToString();
            anun.REMITENTE     = collection["Remitente"].ToString();
            anun.FECHA_ANUNCIO = DateTime.Now;
            var model = bd.CrearAnuncio(anun);

            if (model)
            {
                var result = new { Success = true, Message = "Succes Message" };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var result = new { Success = false, Message = "Error Message" };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }