Exemplo n.º 1
0
            public JsonResult SaveProfile(QAProfile profile)
            {
                try
                {
                    var cs             = new DataSettingsManager().LoadSettings().DataConnectionString;
                    var profileAnswers = profile.ProfileAnswers;
                    using (SqlConnection conn = new SqlConnection(cs))
                    {
                        using (SqlCommand cmd = new SqlCommand("dbo.P_QAUpdateProfile", conn))
                        {
                            var dt = new DataTable();
                            dt.Columns.Add("QuestionId", typeof(Int32));
                            dt.Columns.Add("AnswerId", typeof(Int32));

                            foreach (ProfileAnswer t in profileAnswers)
                            {
                                dt.Rows.Add(t.QuestionId, t.AnswerId);
                            }

                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.Add("@ProfileId", SqlDbType.Int).Value = profile.ProfileId;
                            cmd.Parameters.Add(new SqlParameter("qa", SqlDbType.Structured));
                            cmd.Parameters["qa"].Value = dt;
                            conn.Open();
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, msg = ex.Message, profiles = "+" }, JsonRequestBehavior.AllowGet));
                }

                return(Json(new { success = true, msg = "" }, JsonRequestBehavior.DenyGet));
            }
Exemplo n.º 2
0
            /*det question and answers of some profile*/
            public JsonResult QaProfile()
            {
                List <QAProfile> profiles = new List <QAProfile>();

                try
                {
                    var customer = EngineContext.Current.Resolve <IWorkContext>().CurrentCustomer;

                    var cs = new DataSettingsManager().LoadSettings().DataConnectionString;
                    using (SqlConnection conn = new SqlConnection(cs))
                    {
                        using (SqlCommand cmd = new SqlCommand("dbo.P_QAGetProfile", conn))
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.Add("@CustomerId", SqlDbType.Int).Value = customer.Id;;

                            conn.Open();
                            var rdr = cmd.ExecuteReader();

                            Int32     id      = 0;
                            QAProfile profile = null;
                            while (rdr.Read())
                            {
                                if (rdr.GetInt32(0) != id)
                                {
                                    if (profile != null)
                                    {
                                        profiles.Add(profile);
                                    }
                                    id      = rdr.GetInt32(0);
                                    profile = new QAProfile
                                    {
                                        ProfileId = id,
                                        Name      = rdr.GetString(1)
                                    };
                                }


                                if (rdr.IsDBNull(2))
                                {
                                    continue;                 /*jump to next iteration of while*/
                                }
                                ProfileAnswer profileAnswer = new ProfileAnswer
                                {
                                    QuestionId = rdr.GetInt32(2),
                                    AnswerId   = rdr.GetInt32(3)
                                };

                                profile?.ProfileAnswers.Add(profileAnswer);
                            }
                            rdr.Close();

                            if (profile != null)
                            {
                                profiles.Add(profile);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, msg = ex.Message, profiles = "" }, JsonRequestBehavior.AllowGet));
                }

                return(Json(new { success = true, msg = "", profiles = profiles }, JsonRequestBehavior.AllowGet));

                /*
                 * var requestedETag = Request.Headers["If-None-Match"];
                 * var responseETag = "1e"; // lookup or generate etag however you want
                 * if (requestedETag == responseETag)
                 *  return new HttpStatusCodeResult(HttpStatusCode.NotModified);
                 *
                 * Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
                 * Response.Cache.SetETag(responseETag);
                 *
                 * //if (Request.Headers["If-Modified-Since"] != null && Count % 2 == 0)
                 * //{
                 * //    return new HttpStatusCodeResult((int)HttpStatusCode.NotModified);
                 * //}
                 *
                 * //Response.Cache.SetExpires(DateTime.Now.AddSeconds(5));
                 * //Response.Cache.SetLastModified(DateTime.Now);
                 */
            }