public ActionResult ClickMe()
        {
            //var oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            ////Anonymous type serialized
            //ViewBag.JsonAnonymous = oSerializer.Serialize(new { dinnerTitle = "Veal" }); ;

            ////strong type serialized
            var dinner = new NerdDinnerDomain.Dinner()
            {
                Title = "I'm a dinner",
            };
            //ViewBag.JsonDinner = oSerializer.Serialize(dinner);

            ////unserialized dinner
            //ViewBag.UnserializedDinner = dinner;

            var listOfDinners =
                new List<NerdDinnerDomain.Dinner>()
                    {
                        new Dinner() {Title = "dinner 1", Address="Somewhere one", Country = "USA", EventDate = DateTime.Parse("1/1/2012")},
                        new Dinner() {Title = "dinner 2", Address="Somewhere two", Country = "England", EventDate = DateTime.Parse("1/1/2013")},
                        new Dinner() {Title = "dinner 3", Address="Somewhere three", Country = "France", EventDate = DateTime.Parse("1/1/2014")},
                    };

            ViewBag.ListOfDinners = listOfDinners;
            return View("Index", dinner);
            //return Json(dinner, JsonRequestBehavior.AllowGet);
        }
 public Dinner CreateDinner(Dinner dinner)
 {
     var client = GetAuthorizedHttpClient();
     HttpContent content = this.CreateDinnerContent(dinner);
     var response = client.Post(BaseUri + "Dinner/", content);
     return GetSingleDinnerFromResponse(response);
 }
        public Dinner CreateDinner(Dinner dinner)
        {
            if (_dinners.Where(a => a.DinnerId == dinner.DinnerId).Count() > 0)
                throw new Exception(string.Format("Dinner with Id:{0} already exists", dinner.DinnerId));

            _dinners.Add(dinner);
            return dinner;
        }
 /// <summary>
 /// Creates a dinner
 /// </summary>
 /// <param name="dinner">
 /// The dinner.
 /// </param>
 /// <returns>
 /// the dinner we created
 /// </returns>
 public Dinner CreateDinner(Dinner dinner)
 {
     using (NerdDinnersDb nerdDinnersDb = new NerdDinnersDb())
     {
         nerdDinnersDb.Dinners.Add(dinner);
         nerdDinnersDb.SaveChanges();
         return dinner;
     }
 }
        public void TestCreateDinner()
        {
            var newDinner = new Dinner { CreatedBy = "JohnWickerham", Title = "Sample Dinner 1", EventDate = DateTime.Parse("12/31/2010"), Address = "One Microsoft Way", Country = "USA", HostedBy = "*****@*****.**" };

            DBNerdDinnerOperations operations = new DBNerdDinnerOperations();
            var dinner = operations.CreateDinner(newDinner);

            Assert.IsNotNull(dinner);
        }
        /// <summary>
        /// Update Dinner
        /// </summary>
        /// <param name="dinner">
        /// The dinner.
        /// </param>
        /// <returns>
        /// Returns a Dinner
        /// </returns>
        public Dinner UpdateDinner(Dinner dinner)
        {
            using (NerdDinnersDb nerdDinnersDb = new NerdDinnersDb())
            {
                nerdDinnersDb.Dinners.Attach(dinner);
                nerdDinnersDb.ChangeObjectState(dinner, System.Data.EntityState.Modified);
                nerdDinnersDb.SaveChanges();
            }

            return dinner;
        }
        public ActionResult Edit(Dinner dinner)
        {
            if (ModelState.IsValid)
            {
                var dinnerReturned = this._nerdDinnerService.UpdateDinner(dinner);
                return RedirectToAction("Index", new { dinnerId = dinnerReturned.DinnerId });
            }

            return View(dinner);
        }
        public ActionResult Create(Dinner dinner)
        {
            if (ModelState.IsValid)
            {
                var dinnerReturned = this._nerdDinnerService.CreateDinner(dinner);
                ViewBag.Result = "Your dinner was created successfully";

                return RedirectToAction("Index", new { dinnerId = dinnerReturned.DinnerId });
            }

            return View(dinner);
        }
 private HttpContent CreateDinnerContent(Dinner dinnerToUpdate)
 {
     DataContractSerializer singleSerializer = new DataContractSerializer(typeof(Dinner));
     HttpContent content = dinnerToUpdate.ToContentUsingDataContractSerializer(singleSerializer);
     content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/xml");
     return content;
 }
        public Dinner UpdateDinner(Dinner dinner)
        {
            var dinnerToUpdate = _dinners.Where(a => a.DinnerId == dinner.DinnerId).FirstOrDefault();

            if (dinnerToUpdate == null)
                throw new Exception(string.Format("Dinner with Id:{0} does not exist", dinner.DinnerId));

            _dinners.Remove(dinnerToUpdate);
            _dinners.Add(dinner);
            return dinner;
        }