//public ActionResult Create(GuestBook Model, Guid? id = null)
        public ActionResult Create(Guid?id = null, string Magic = null)
        {
            //if (!ModelState.IsValid)
            //{
            //    return View();
            //}

            var Model    = new GuestBook();
            var identity = Request.RequestContext.HttpContext.User.Identity as FormsIdentity;
            var o        = JObject.Parse(identity.Ticket.UserData);

            // create data.
            using (WorkshopDb db = new WorkshopDb())
            {
                if (id == null)
                {
                    Model.Id          = Guid.NewGuid();
                    Model.DateCreated = DateTime.Now;
                    Model.Subject     = Request.Form["Subject"];
                    Model.Name        = o.Property("name").ToObject(typeof(string)).ToString();
                    Model.Email       = o.Property("email").ToObject(typeof(string)).ToString();
                    Model.Body        = Sanitizer.GetSafeHtmlFragment(Request.Unvalidated.Form["Body"]);

                    db.GuestBooks.Add(Model);
                }
                else
                {
                    Model.Id          = Guid.NewGuid();
                    Model.IdReply     = id.Value;
                    Model.Subject     = Request.Form["Subject"];
                    Model.Name        = o.Property("name").ToObject(typeof(string)).ToString();
                    Model.Email       = o.Property("email").ToObject(typeof(string)).ToString();
                    Model.Body        = Sanitizer.GetSafeHtmlFragment(Request.Unvalidated.Form["Body"]);
                    Model.DateCreated = DateTime.Now;

                    db.GuestBooks.Add(Model);
                }

                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(Guid id)
        {
            // create data.
            using (WorkshopDb db = new WorkshopDb())
            {
                // query item.
                var query = db.GuestBooks.Where(i => i.Id == id);

                if (!query.Any())
                {
                    return(HttpNotFound());
                }

                var dbModel = query.First();
                db.GuestBooks.Remove(dbModel);

                // change tracking service lets it valid.
                db.SaveChanges();
            }

            return(new EmptyResult());
        }
        //public ActionResult Edit(GuestBook Model, Guid id)
        public ActionResult Edit(Guid id, string Magic = null)
        {
            //if (!ModelState.IsValid)
            //{
            //    if (string.IsNullOrEmpty(Model.Subject) ||
            //        string.IsNullOrEmpty(Model.Body))
            //        return View();
            //}

            if (string.IsNullOrEmpty(Request.Form["Subject"]) ||
                string.IsNullOrEmpty(Request.Unvalidated.Form["Body"]))
            {
                return(View());
            }

            // create data.
            using (WorkshopDb db = new WorkshopDb())
            {
                // query item.
                var query = db.GuestBooks.Where(i => i.Id == id);

                if (!query.Any())
                {
                    return(HttpNotFound());
                }

                var dbModel = query.First();

                // modify data.
                dbModel.Subject = Request.Form["Subject"];
                dbModel.Body    = Sanitizer.GetSafeHtmlFragment(Request.Unvalidated.Form["Body"]);

                // change tracking service lets it valid.
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }