Пример #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));
        }
Пример #2
0
        public IHttpActionResult Postuser([FromBody] User user)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Not a valid model"));
                }

                using (CITIZENPULSEEntities3 dc = new CITIZENPULSEEntities3())
                {
                    dc.Users.Add(user);
                    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 = user.userid }, user));
        }
Пример #3
0
        public ActionResult survey(Survey sur)
        {
            try
            {
                //  sur.status = "completed";
                //sur.Duration_days_ = 7;
                #region save to database
                using (CITIZENPULSEEntities3 dc = new CITIZENPULSEEntities3())
                {
                    if (ModelState.IsValid)
                    {
                        sur.status         = "completed";
                        sur.Duration_days_ = 7;


                        dc.Surveys.Add(sur);

                        dc.SaveChanges();

                        TempData["survey"] = sur;
                        return(RedirectToAction("displaySur"));
                    }
                }



                ViewBag.categoryId = new SelectList(db.Categories, "categoryId", "categoryId", sur.categoryId);
                ViewBag.customerId = new SelectList(db.Customers, "customerId", "customerId", sur.customerId);
                return(View(sur));
            }
            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;
            }

            #endregion
        }
Пример #4
0
        public ActionResult Questions(Question ques)

        {
            try
            {
                #region save to database
                using (CITIZENPULSEEntities3 dc = new CITIZENPULSEEntities3())
                {
                    if (ModelState.IsValid)
                    {
                        ques.Isdeleted = false;
                        ques.typeId    = 1;
                        dc.Questions.Add(ques);
                        dc.SaveChanges();



                        TempData["Questions"] = ques;
                        return(RedirectToAction("Optionn"));
                    }
                }


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

                ViewBag.customerId = new SelectList(db.Customers, "customerId", "customerId");

                return(View(ques));
            }
            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;
            }

            #endregion
        }
Пример #5
0
        public ActionResult category(Category cat)
        {
            try
            {
                #region save to database
                using (CITIZENPULSEEntities3 dc = new CITIZENPULSEEntities3())
                {
                    if (ModelState.IsValid)
                    {
                        dc.Categories.Add(cat);
                        dc.SaveChanges();
                        //                        return RedirectToAction("Index");

                        TempData["category"] = cat;
                        return(RedirectToAction("displayCat"));
                    }
                }



                ViewBag.customerId = new SelectList(db.Customers, "customerId", "customerId");

                return(View(cat));
            }

            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;
            }
        }
        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;
            }
        }
Пример #7
0
        public ActionResult Registration([Bind(Exclude = "IsActive")] User user)

        {
            bool   Status  = false;
            string Message = "";

            //model validation
            if (ModelState.IsValid)
            {
                #region
                var isExist = IsEmailExist(user.email);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "email alredy exist");
                    return(View(user));
                }

                #endregion

                #region passwaord hash
                user.password        = Crypto.hash(user.password);
                user.ConfirmPassword = Crypto.hash(user.ConfirmPassword);
                #endregion
                user.IsActive = true;
                try
                {
                    #region save to database
                    using (CITIZENPULSEEntities3 dc = new CITIZENPULSEEntities3())
                    {
                        dc.Users.Add(user);
                        dc.SaveChanges();
                    }

                    TempData["Registraion"] = user;
                    return(RedirectToAction("Regiation"));
                }
                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;
                }


                #endregion
            }
            else
            {
                Message = "invalid request";
            }


            return(View(user));
        }