Exemplo n.º 1
0
        public ActionResult Add(Post post)
        {
            if (ModelState.IsValid)
            {
                post.Created = DateTime.Now;
                post.LastModified = DateTime.Now;
                //post.Status = 1;
                post.Author = 1;

                MudHookNotifications.Set(new Notification("success", "Your new post has been added"));

                repo.AddPost(post);
                return RedirectToAction("Index");
            }
            else
            {
                var allErrors = ModelState.Values.SelectMany(v => v.Errors);
                string message = "";
                foreach (var e in allErrors)
                {
                    message += e.ErrorMessage + ",";
                }
                MudHookNotifications.Set(new Notification("error", message.TrimEnd()));
            }

            return View(post);
        }
Exemplo n.º 2
0
 public ActionResult Edit(Post post)
 {
     if (ModelState.IsValid)
     {
         repo.EditPost(post);
         MudHookNotifications.Set(new Notification("success", "Your post has been updated."));
         return RedirectToAction("Index");
     }
     return View(post);
 }
Exemplo n.º 3
0
 public void AddPost(Post post)
 {
     db.Posts.Add(post);
 }
Exemplo n.º 4
0
 public void EditPost(Post post)
 {
     db.Entry(post).State = EntityState.Modified;
     Save();
 }