public async Task Insert(object obj)
        {
            ArticleAndReplyModel replyModel = obj as ArticleAndReplyModel;

            replyModel.reply.ID          = Guid.NewGuid();
            replyModel.reply.CreateUser  = HttpContext.Current.User.Identity.Name;
            replyModel.reply.PublichDate = DateTime.Now;
            MainArticleModel article = await db.MainArticles.FindAsync(replyModel.reply.ArticleID);

            article.ReplyCount = article.replyArticles.ToList().Count() + 1;
            db.Replies.Add(replyModel.reply);
            await dbSave.Save(db);
        }
Esempio n. 2
0
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MainArticleModel article = db.MainArticles.Find(id);

            if (article == null)
            {
                return(HttpNotFound());
            }
            ArticleAndReplyModel articleModel = new ArticleAndReplyModel();

            articleModel.article = article;
            articleModel.reply   = new ReplyModel();
            return(View(articleModel));
        }
Esempio n. 3
0
        public async Task <ActionResult> Details(ArticleAndReplyModel replyModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string subject = TempData["subject"].ToString();
                    replyModel.reply.ArticleID    = db.MainArticles.Where(u => u.ID.ToString().Equals(subject)).Single().ID;
                    replyModel.reply.ArticelMaker = db.MainArticles.Where(u => u.ID.Equals(replyModel.reply.ArticleID)).SingleOrDefault().CreateUser;
                    repository = new ReplyModelRepository(db);
                    await repository.Insert(replyModel);

                    return(RedirectToAction("Details", "MainArticleModels", new { id = replyModel.reply.ArticleID }));
                }
            }
            catch (DataException)
            {
                return(RedirectToAction("DataError", "Error", new { message = "用戶儲存錯誤" }));
            }
            return(View(replyModel));
        }