コード例 #1
0
        public ActionResult Update(UserSession userSession)
        {
            if (!ModelState.IsValid)
            {
                return Json(ModelState.Values);
            }

            var session = MvcApplication.UserSession
                                        .Where(u => u.Id == userSession.Id)
                                        .FirstOrDefault();

            session.Name = userSession.Name;
            session.Tags.Clear();
            session.Tags.AddRange(userSession.Tags);

            if (Request.IsAjaxRequest())
            {
                return Json(session, JsonRequestBehavior.AllowGet);
            }

            return RedirectToAction("Index");
        }
コード例 #2
0
        public ActionResult Create(UserSession userSession)
        {
            if(!ModelState.IsValid)
            {
                return Json(ModelState.Values);
            }

            userSession.Id = Guid.NewGuid();

            userSession.Tags.Add("Test 1");
            userSession.Tags.Add("Test 2");
            userSession.Tags.Add("Test 3");
            userSession.Tags.Add("Test 4");

            MvcApplication.UserSession.Add(userSession);

            if(Request.IsAjaxRequest())
            {
                return Json(userSession, JsonRequestBehavior.AllowGet);
            }

            return RedirectToAction("Index");
        }