Example #1
0
 public ActionResult AddEditNoticia(AddEditNoticiaViewModel ViewModel)
 {
     if (!ModelState.IsValid)
     {
         ViewModel.EdificioId = ViewModel.EdificioId;
         ViewModel.Fill(CargarDatosContext());
         return(View(ViewModel));
     }
     try
     {
         if (ViewModel.NoticiaId.HasValue)
         {
             Noticia noticia = context.Noticia.FirstOrDefault(x => x.NoticiaId == ViewModel.NoticiaId.Value);
             noticia.Titulo  = ViewModel.Titulo;
             noticia.Sumilla = ViewModel.Sumilla;
             noticia.Detalle = ViewModel.Detalle;
             context.Entry(noticia).State = System.Data.Entity.EntityState.Modified;
         }
         else
         {
             Noticia noticia = new Noticia();
             noticia.Titulo     = ViewModel.Titulo;
             noticia.Sumilla    = ViewModel.Sumilla;
             noticia.Detalle    = ViewModel.Detalle;
             noticia.Estado     = ConstantHelpers.EstadoActivo;
             noticia.EdificioId = ViewModel.EdificioId;
             noticia.Fecha      = DateTime.Now;
             context.Noticia.Add(noticia);
         }
         context.SaveChanges();
         PostMessage(MessageType.Success);
     }
     catch { PostMessage(MessageType.Error); }
     return(RedirectToAction("LstNoticiaAdm", new { EdificioId = ViewModel.EdificioId }));
 }
Example #2
0
        public ActionResult AddEditNoticia(Int32?NoticiaId, Int32 EdificioId)
        {
            AddEditNoticiaViewModel ViewModel = new AddEditNoticiaViewModel();

            ViewModel.EdificioId = EdificioId;
            ViewModel.NoticiaId  = NoticiaId;
            ViewModel.Fill(CargarDatosContext());
            return(View(ViewModel));
        }