示例#1
0
        public ActionResult Create([Bind(Include = "Id,Title,Body,Created,TopicId")] ReplyViewModel replyViewModel)
        {
            if (ModelState.IsValid)
            {
                Reply reply = new Reply
                {
                    //Id = replyViewModel.Id,
                    Title   = replyViewModel.Title,
                    Body    = replyViewModel.Body,
                    Created = replyViewModel.Created,
                    TopicId = replyViewModel.TopicId
                };
                _repo.AddReply(reply);
                _repo.Save();

                replyViewModel.Topics = _repo.GetTopics().ToList().Select(x => new SelectListItem
                {
                    Value = x.Id.ToString(),
                    Text  = x.Title
                });

                //return RedirectToAction("Index");
            }

            return(View(replyViewModel));
        }
示例#2
0
        public HttpResponseMessage Post(int topicid, [FromBody] Reply newReply)
        {
            if (newReply.Created == default(DateTime))
            {
                newReply.Created = DateTime.UtcNow;
            }

            newReply.TopicId = topicid;

            if (_repo.AddReply(newReply) && _repo.Save())
            {
                return(Request.CreateResponse(HttpStatusCode.Created, newReply));
            }

            return(Request.CreateResponse(HttpStatusCode.BadRequest));
        }