Exemple #1
0
        public ActionResult Create(Entry newEntry)
        {
            if (ModelState.IsValid)
            {
                db.Entries.Add(newEntry);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(newEntry);
        }
        /*[HttpPost]*/
        /*[AllowCrossSiteJson]*/
        public void Insert(string[] JsonData)
        {
            /*
            string[] JsonData = new string[1];
            JsonData[0] = "{\"Id\":1,\"title\":\"Första inlägget från Offline insert\",\"input\":\"Här skulle man väl kunna skriva vad man vill egentligen..\",\"date\":\"2015\",\"Offline\" : \"true\"}";
             */
            Entry e;
            for (int i = 0; i < JsonData.Length; i++)
            {
                var jobject = System.Web.Helpers.Json.Decode(JsonData[i]);

                e = new Entry { title = jobject.title, input = jobject.input, date = DateTime.Now, Offline = Convert.ToBoolean(jobject.Offline) };
                db.Entries.Add(e);
                db.SaveChanges();

            }
        }
Exemple #3
0
        public void Upload([FromBody]string value)
        {
            Console.Write(value);

            dynamic jsonObj = JsonConvert.DeserializeObject(value);

            Entry e;
            foreach (var item in jsonObj)
            {

                if (item.Id != null)
                {
                    int id = item.Id;
                    Entry existingEntry = db.Entries.Find(id);

                    //Uppdatera inlägget. Det har blivit ändrat offline, men inte skapat där.
                    existingEntry.title = item.title;
                    existingEntry.input = item.input;
                    existingEntry.date = item.date;

                    db.Entry(existingEntry).State = EntityState.Modified;
                    db.SaveChanges();

                }

                else
                {
                    e = new Entry
                    {
                        title = item.title,
                        input = item.input,
                        date = item.date,
                    };
                    db.Entries.Add(e);
                    db.SaveChanges();
                }

            }
        }
Exemple #4
0
        public void FillWithExampleEntries()
        {
            Entry e = new Entry
                {
                    title = "En dag i taget",
                    input = "Lorem ipsum dolor sit amet, idque posidonium appellantur duo cu, et mel solum everti. Eum ea harum iudicabit. Ei discere legendos est. Rebum deleniti deseruisse eu mei, illum minim est eu. Semper placerat phaedrum ea his.",
                    date = new DateTime(2015, 11, 10, 1, 1, 1)
                };

                db.Entries.Add(e);
                db.SaveChanges();

                    e = new Entry
                {
                    title = "Fiskare",
                    input = "Ut qui augue graecis detracto, per eu tempor nominati oportere. An fierent comprehensam eam, his putent doctus no. Id sint dicunt omittam vim. Nam ea alii zril.",
                    date = new DateTime(2015, 12, 11, 2, 2, 2)
                };

                db.Entries.Add(e);
                db.SaveChanges();
                    e = new Entry
                    {
                        title = "Jazzigt!",
                        input = "Ei vix simul consul consequuntur, equidem definiebas vim ex, mel posse nostrum maiestatis ut. Te vix facilis feugait adversarium, et suas audiam elaboraret nec. Cu pri decore equidem. Stet doctus adolescens ne sea.",
                        date = new DateTime(2015, 12, 24, 3, 1, 4)
                    };

                db.Entries.Add(e);
                db.SaveChanges();
        }