示例#1
0
        public ActionResult FollowTopic(FormCollection fc)
        {
            if (!AuthorizeUser())
            {
                return(RedirectToAction("Login", "Accounts"));
            }

            try
            {
                var user_id = int.Parse(Session["user_id"].ToString());

                // feed follow
                var selectedTopics = fc["selectedTopics"].Split(',').ToList();

                FollowTopicRepository topicRepository = new FollowTopicRepository();
                topicRepository.DeleteByUser(user_id);
                topicRepository.AddTopics(user_id, selectedTopics);

                return(RedirectToAction("Feed"));
            }
            catch
            {
                ViewBag.Message = "Failed to follow the selected topics";
                return(View());
            }
        }
示例#2
0
        public HttpResponseMessage PostTopics(int user_id, [FromBody] List <string> topicList)
        {
            try
            {
                if (topicList.Count >= 1)
                {
                    ftrepo.AddTopics(user_id, topicList);
                    var resp = Request.CreateResponse(HttpStatusCode.Created);
                    //resp.Headers.Location = new Uri(new Uri(Request.RequestUri, ".") + entity.TopicFollowID.ToString());
                    return(resp);
                }

                else
                {
                    // TODO: Maybe return something else instead of no content
                    return(Request.CreateResponse(HttpStatusCode.NoContent, "No topics added"));
                }
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Failed to create new topics." + e));
            }
        }