public DailyReflectionReflection Create(DailyReflectionReflection model)
        {
            var dailyReflectionReflection = new DailyReflectionReflection();

            using (var dbconn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString))
            {
                if (dbconn.State == ConnectionState.Open)
                {
                    dbconn.Close();
                }
                dbconn.Open();

                using (var cmd = new SqlCommand("spInsertUserDailyReflectionReflection", dbconn))
                {
                    try
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@userID", model.UserId);
                        cmd.Parameters.AddWithValue("@reflectionID", model.DailyReflectionId);
                        cmd.Parameters.AddWithValue("@title", model.Title);
                        cmd.Parameters.AddWithValue("@content", model.ReflectionContent);


                        var reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            dailyReflectionReflection = _reflectionReflectionTransformer.Transform(reader);
                            dailyReflectionReflection.DailyReflection = _dailyReflectionTransformer.Transform(reader);
                            dailyReflectionReflection.User            = _userTransformer.Transform(reader);
                        }
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }
            }

            return(dailyReflectionReflection);
        }
예제 #2
0
        public DailyReflectionReflection GetUserReflection(int userId, int reflectionId)
        {
            var reflectionReflectionTransformer = new ReflectionReflectionTransformer();
            var reflection = new DailyReflectionReflection();

            using (var sp = new StoredProcedure("spGetUserDailyReflectionReflection"))
            {
                sp.SqlCommand.Parameters.AddWithValue("@userID", userId);
                sp.SqlCommand.Parameters.AddWithValue("@reflectionID", reflectionId);

                var dr = sp.SqlCommand.ExecuteReader();

                while (dr.Read())
                {
                    reflection = reflectionReflectionTransformer.Transform(dr);
                    reflection.ReflectionDate = Convert.ToDateTime(dr["DateOfReflection"]);
                }
            }

            return(reflection);
        }
        public DailyReflectionReflection GetUserReflection(int userId, int reflectionId)
        {
            var reflectionReflectionTransformer = new ReflectionReflectionTransformer();
            var reflection = new DailyReflectionReflection();

            using (var dbconn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString))
            {
                if (dbconn.State == ConnectionState.Open)
                {
                    dbconn.Close();
                }
                dbconn.Open();

                using (var cmd = new SqlCommand("spGetUserDailyReflectionReflection", dbconn))
                {
                    try
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@userID", userId);
                        cmd.Parameters.AddWithValue("@reflectionID", reflectionId);


                        var dr = cmd.ExecuteReader();

                        while (dr.Read())
                        {
                            reflection = reflectionReflectionTransformer.Transform(dr);
                            reflection.ReflectionDate = Convert.ToDateTime(dr["DateOfReflection"]);
                        }
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }
            }

            return(reflection);
        }