Ejemplo n.º 1
0
        public IHttpActionResult PostAResponse([FromBody] sur_response res)
        {
            try {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Not a valid model"));
                }

                using (CITIZENPULSEEntities3 dc = new CITIZENPULSEEntities3())
                {
                    // var mn = res.SurveyId;
                    //var ny = res.Respondon;
                    dc.sur_response.Add(res);
                    dc.SaveChanges();
                }
            }

            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }

            return(CreatedAtRoute("DefaultApi", new { id = res.responseId }, res));
        }
        public ActionResult Sresponse(sur_response respo)
        {
            try
            {
                #region save to database
                using (CITIZENPULSEEntities3 dc = new CITIZENPULSEEntities3())
                {
                    if (ModelState.IsValid)
                    {
                        dc.sur_response.Add(respo);
                        dc.SaveChanges();
                        //                        return RedirectToAction("Index");
                    }
                }



                ViewBag.SurveyId = new SelectList(db.Surveys, "SurveyId", "SurveyId");

                return(View(respo));
            }

            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }
        }