public ActionResult Add(FormCollection collection)
        {
            string title = collection["title"];
            int categoryId = int.Parse(collection["category"]);
            string description = collection["description"];
            string url = collection["url"];
            string reason = collection["reason"];
            string score = collection["score"];

            //添加一个分享
            Share share = new Share();
            share.ShareNum = CommomHelper.GetRandomNum();
            share.Title = title;
            share.CategoryId = categoryId;
            share.Description = description;
            share.Url = url;
            share.SharedBy = cookie.UserId;
            share.SharedAt = DateTime.Now;

            context.Shares.AddObject(share);
            context.SaveChanges();

            //添加分享理由,即原始评论
            Comment comment = new Comment();
            comment.ShareId = share.ShareId;
            comment.Grade = int.Parse(score);
            comment.Description = reason;
            comment.IsOriginal = true;
            comment.CommentedBy = cookie.UserId;
            comment.CommentedAt = DateTime.Now;
            context.Comments.AddObject(comment);
            context.SaveChanges();

            return Redirect("/Home/Index");
        }
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         // TODO: Add insert logic here
         Share share = new Share();
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
Пример #3
0
        private void Fixupshare(Share previousValue)
        {
            if (IsDeserializing)
            {
                return;
            }

            if (previousValue != null && previousValue.comments.Contains(this))
            {
                previousValue.comments.Remove(this);
            }

            if (share != null)
            {
                if (!share.comments.Contains(this))
                {
                    share.comments.Add(this);
                }

                ShareId = share.ShareId;
            }
            if (ChangeTracker.ChangeTrackingEnabled)
            {
                if (ChangeTracker.OriginalValues.ContainsKey("share")
                    && (ChangeTracker.OriginalValues["share"] == share))
                {
                    ChangeTracker.OriginalValues.Remove("share");
                }
                else
                {
                    ChangeTracker.RecordOriginalValue("share", previousValue);
                }
                if (share != null && !share.ChangeTracker.ChangeTrackingEnabled)
                {
                    share.StartTracking();
                }
            }
        }
Пример #4
0
        private void FixupShare(Share previousValue, bool skipKeys = false)
        {
            if (IsDeserializing)
            {
                return;
            }

            if (previousValue != null && previousValue.Votes.Contains(this))
            {
                previousValue.Votes.Remove(this);
            }

            if (Share != null)
            {
                if (!Share.Votes.Contains(this))
                {
                    Share.Votes.Add(this);
                }

                ShareId = Share.ShareId;
            }
            else if (!skipKeys)
            {
                ShareId = null;
            }

            if (ChangeTracker.ChangeTrackingEnabled)
            {
                if (ChangeTracker.OriginalValues.ContainsKey("Share")
                    && (ChangeTracker.OriginalValues["Share"] == Share))
                {
                    ChangeTracker.OriginalValues.Remove("Share");
                }
                else
                {
                    ChangeTracker.RecordOriginalValue("Share", previousValue);
                }
                if (Share != null && !Share.ChangeTracker.ChangeTrackingEnabled)
                {
                    Share.StartTracking();
                }
            }
        }