Beispiel #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));
        }
        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));
        }
        //// .../api/v1/topics
        //// .../api/v1/topics?includereplies=true
        //public IEnumerable<Topic> Get(bool IncludeReplies = false)
        //{
        //    IQueryable<Topic> results;
        //    if (IncludeReplies == true)
        //    {
        //        results = _repo.GetTopicsIncludingReplies();
        //    }
        //    else
        //    {
        //        results = _repo.GetTopics();

        //    }
        //    var topics = results.OrderByDescending(t => t.Created)
        //        .Take(25)
        //        .ToList();


        //    return topics;
        //}

        public HttpResponseMessage Post([FromBody] Topic newTopic)
        {
            if (newTopic.Created == default(DateTime))
            {
                newTopic.Created = DateTime.UtcNow;
            }

            newTopic.QuestionnaireId = "01549318-6C6E-4C65-A2E5-94662509970E"; //TODO
            newTopic.UserId          = "TODO_UserID";

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

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