public ActionResult Create([Bind(Include = "ContentId,Text,Note,Reference")] Content content)
        {
            //string baseUrl = "https://openlibrary.org/api/books?bibkeys=ISBN:{0}&jscmd=details&format=json";
            //var url = string.Format(baseUrl, content.Reference);

            //var syncClient = new WebClient();
            //var data = syncClient.DownloadString(url);

            //JObject o = JObject.Parse(data);

            //string author = (string)o["ISBN:" + content.Reference]["details"]["authors"][0]["name"];
            //string[] authorArray = author.Split(' ');
            //string surname = authorArray.Last();
            //string initial = authorArray[0][0] + ".";

            //string publish_date = (string)o["ISBN:" + content.Reference]["details"]["publish_date"];

            //string title = (string)o["ISBN:" + content.Reference]["details"]["title"];

            //string publish_places = (string)o["ISBN:" + content.Reference]["details"]["publish_places"][0];
            //string[] publish_placesArray = publish_places.Split(' ');
            //string publish_city = publish_placesArray.First();
            //string publishers = (string)o["ISBN:" + content.Reference]["details"]["publishers"][0];

            //string citation = surname + ", " + initial + " (" + publish_date + "). <i>" +
            //    title + "</i> (p. pages_used). " + publish_city + ": " + publishers + ".";

            //content.Reference = citation;


            content.TimeUpdated = DateTime.Now;

            if (ModelState.IsValid)
            {
                db.Contents.Add(content);
                db.SaveChanges();
                //return RedirectToAction("Index");
                //return RedirectToAction("Create", "UserContents");

                string userid    = User.Identity.GetUserId();
                int    contentid = content.ContentId;

                var result = new UserContentsController().Create(new UserContent(userid, contentid));

                return(RedirectToAction("Index", "UserContents"));
            }

            return(View(content));
        }
Exemple #2
0
        public ActionResult Create([Bind(Include = "ContentId,Text,Note,Reference")] Content content)
        {
            content.TimeUpdated = DateTime.Now;

            if (ModelState.IsValid)
            {
                db.Contents.Add(content);
                db.SaveChanges();
                //return RedirectToAction("Index");
                //return RedirectToAction("Create", "UserContents");

                string userid    = User.Identity.GetUserId();
                int    contentid = content.ContentId;

                var result = new UserContentsController().Create(new UserContent(userid, contentid));

                return(RedirectToAction("Index", "UserContents"));
            }

            return(View(content));
        }