コード例 #1
0
        public ActionResult Edit(Survey model)
        {
            foreach (var question in model.Questions)
            {
                question.SurveyId = model.Id;

                if (question.Id == 0)
                {
                    question.CreatedOn        = DateTime.Now;
                    question.ModifiedOn       = DateTime.Now;
                    _db.Entry(question).State = EntityState.Added;
                }
                else
                {
                    question.ModifiedOn       = DateTime.Now;
                    _db.Entry(question).State = EntityState.Modified;
                    _db.Entry(question).Property(x => x.CreatedOn).IsModified = false;
                }
            }
            // Only created user can edit.
            model.CreatedByUserId  = User.Identity.GetUserId();
            _db.Entry(model).State = EntityState.Modified;
            _db.SaveChanges();
            TempData["info"] = "The survey was successfully updated!";
            return(RedirectToAction("Edit", new { id = model.Id }));
            //return View(model);
        }
コード例 #2
0
        public ActionResult Delete(int surveyId, int id, string returnTo)
        {
            var response = new Response()
            {
                Id = id, SurveyId = surveyId
            };

            _db.Entry(response).State = EntityState.Deleted;
            _db.SaveChanges();
            TempData["success"] = "Your response was successfully deleted!";

            var url = Url.Action("Survey", "Reports", new { id = surveyId });

            return(Json(url));
        }