Esempio 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);
        }
Esempio 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);
 }
Esempio n. 3
0
 public void AddPost(Post post)
 {
     db.Posts.Add(post);
 }
Esempio n. 4
0
 public void EditPost(Post post)
 {
     db.Entry(post).State = EntityState.Modified;
     Save();
 }