Ejemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            EC_News ec_news = db.EC_News.Find(id);

            db.EC_News.Remove(ec_news);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        //
        // GET: /News2/Delete/5

        public ActionResult Delete(int id = 0)
        {
            EC_News ec_news = db.EC_News.Find(id);

            if (ec_news == null)
            {
                return(HttpNotFound());
            }
            return(View(ec_news));
        }
Ejemplo n.º 3
0
 public ActionResult Edit(EC_News ec_news)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ec_news).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Author = new SelectList(db.EC_Users, "Id", "Username", ec_news.Author);
     return(View(ec_news));
 }
Ejemplo n.º 4
0
        public ActionResult Edit(int id = 0)
        {
            EC_News ec_news = db.EC_News.Find(id);

            if (ec_news == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Author = new SelectList(db.EC_Users, "Id", "Username", ec_news.Author);
            return(View(ec_news));
        }
Ejemplo n.º 5
0
        public ActionResult Create(EC_News ec_news)
        {
            if (ModelState.IsValid)
            {
                db.EC_News.Add(ec_news);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Author = new SelectList(db.EC_Users, "Id", "Username", ec_news.Author);
            return(View(ec_news));
        }
Ejemplo n.º 6
0
        public static EC_News TranslateNewsViewModel(NewsViewModel model)
        {
            EC_News _new = new EC_News();

            if (model != null)
            {
                _new.Title       = model.Title;
                _new.thumbnail   = model.thumbnail;
                _new.link        = model.thumbnail;
                _new.Description = model.Description;
                _new.Author      = model.Author;
                return(_new);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 7
0
        public ActionResult Create(NewsViewModel _new)
        {
            //To do tomar el usuario en sesión
            _new.Author = 1;
            if (ModelState.IsValid)
            {
                EC_News ec_news = new EC_News();
                ec_news        = NewsViewModel.TranslateNewsViewModel(_new);
                ec_news.Author = 1;
                db.EC_News.Add(ec_news);

                try
                {
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (DbEntityValidationException ex)
                {
                    StringBuilder sb = new StringBuilder();

                    foreach (var failure in ex.EntityValidationErrors)
                    {
                        sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                        foreach (var error in failure.ValidationErrors)
                        {
                            sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                            sb.AppendLine();
                        }
                    }

                    throw new DbEntityValidationException(
                              "Entity Validation Failed - errors follow:\n" +
                              sb.ToString(), ex
                              );
                }
            }

            return(View(_new));
        }