Exemplo n.º 1
0
 public ActionResult Edit(int id, Topic model)
 {
     try
     {
         // TODO: Add update logic here
         if (!ModelState.IsValid)
         {
             return(View(model));
         }
         else
         {
             var data = _db.Topics.Find(id);
             model.CreateBy   = data.CreateBy;
             model.CreateDate = data.CreateDate;
             model.EditBy     = Author.GetId(User.Identity.Name);
             model.EditDate   = DateTime.Now;
             _db.Entry(data).CurrentValues.SetValues(model);
             _db.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(model));
     }
 }
Exemplo n.º 2
0
 public ActionResult Edit(int id, Config model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(View(model));
         }
         else
         {
             if (String.IsNullOrEmpty(model.Title) && !String.IsNullOrEmpty(model.Name))
             {
                 model.Title = SEA.Heplers.CreateDefault.CreateDefaultTitle(model.Name);
             }
             var author = Author.GetId(User.Identity.Name);
             model.CreateBy   = author;
             model.CreateDate = DateTime.Now;
             model.EditBy     = author;
             model.EditDate   = DateTime.Now;
             _db.Entry(data).CurrentValues.SetValues(model);
             _db.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(model));
     }
 }
Exemplo n.º 3
0
 public static int IsCheckArticleUpdate(article article)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         db.Entry(article).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(1);
     }
 }
Exemplo n.º 4
0
 public ActionResult Edit(Post post)
 {
     if (ModelState.IsValid)
     {
         db.Entry(post).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AuthorID = new SelectList(db.Authors, "AuthorID", "Name", post.AuthorID);
     return(View(post));
 }
Exemplo n.º 5
0
 public ActionResult Edit(Comment comment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(comment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PostID = new SelectList(db.Posts, "PostID", "Username", comment.PostID);
     return(View(comment));
 }
Exemplo n.º 6
0
        public ActionResult Edit(int id, Post model, string ListTopic)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var post = _db.Posts.Find(id);
                    ViewBag.ListTopic = post.Topics.Select(x => x.Name).ToList();
                    return(View(model));
                }
                else
                {
                    var post = _db.Posts.Find(id);
                    if (model.Title == post.Title && model.Name != post.Name)
                    {
                        model.Title = post.Name;
                    }
                    model.CreateBy   = post.CreateBy;
                    model.CreateDate = post.CreateDate;
                    model.EditBy     = Author.GetId(User.Identity.Name);
                    model.EditDate   = DateTime.Now;
                    _db.Entry(post).CurrentValues.SetValues(model);
                    _db.SaveChanges();
                    List <Topic> remove = new List <Topic>();
                    List <Topic> add    = new List <Topic>();
                    var          check  = CheckListTopic(post.Topics.Select(x => x.Name).ToList(), ListTopic, ref add, ref remove);
                    if (check == true)
                    {
                        foreach (var item in remove)
                        {
                            post.Topics.Remove(item);
                        }
                        foreach (var item in add)
                        {
                            post.Topics.Add(item);
                        }
                        _db.SaveChanges();
                    }
                }
                // TODO: Add update logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(model));
            }
        }
Exemplo n.º 7
0
 public static int IsCheckUpdateLinks(int linkId, string title, string url, string desc)
 {
     using (MyBlogEntities db = new MyBlogEntities())
     {
         var result = from l in db.link where l.title == title select l;
         if (result.Count() > 0)
         {
             return(0);
         }
         else
         {
             link link = db.link.Find(linkId);
             link.title           = title;
             link.url             = url;
             link.desc            = desc;
             db.Entry(link).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             return(1);
         }
     }
 }
Exemplo n.º 8
0
 public T Update(T obj)
 {
     _db.Entry <T>(obj).State = System.Data.Entity.EntityState.Modified;
     return(obj);
 }