Esempio n. 1
0
        public static int Insert(SceneAddRequest model)
        {
            int id = 0;

            using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.CommandText = "dbo.Scene_Insert";

                    MapCommonSceneParameters(model, cmd);
                    cmd.Parameters.AddWithValue("@UserIdCreated", _getId());
                    SqlParameter outputId = new SqlParameter("@Id", System.Data.SqlDbType.Int)
                    {
                        Direction = System.Data.ParameterDirection.Output
                    };
                    cmd.Parameters.Add(outputId);

                    cmd.ExecuteNonQuery();

                    id = (int)outputId.Value;
                }
                conn.Close();
            }
            return(id);
        }
Esempio n. 2
0
        public HttpResponseMessage Insert(SceneAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
            }
            ItemResponse <int> response = new ItemResponse <int>();

            response.Item = SceneService.Insert(model);
            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Esempio n. 3
0
 private static void MapCommonSceneParameters(SceneAddRequest model, SqlCommand cmd)
 {
     cmd.Parameters.AddWithValue("@SequenceId", model.SequenceId);
     cmd.Parameters.AddWithValue("@Title", model.Title ?? String.Empty);
     cmd.Parameters.AddWithValue("@Summary", model.Summary ?? String.Empty);
     cmd.Parameters.AddWithValue("@ProtagonistId", model.ProtagonistId);
     cmd.Parameters.AddWithValue("@AntagonistId", model.AntagonistId);
     cmd.Parameters.AddWithValue("@Conflict", model.Conflict ?? String.Empty);
     cmd.Parameters.AddWithValue("@PhysicalGoal", model.PhysicalGoal ?? String.Empty);
     cmd.Parameters.AddWithValue("@EmotionalGoal", model.EmotionalGoal ?? String.Empty);
     cmd.Parameters.AddWithValue("@Turn", model.Turn ?? String.Empty);
     cmd.Parameters.AddWithValue("@Setting", model.Setting ?? String.Empty);
 }
Esempio n. 4
0
        public static int ScenesUpdate(SequenceScenesUpdateRequest model)
        {
            int id = 0;

            using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.CommandText = "dbo.Sequence_ScenesUpdate";

                    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(SceneUpdateRequest));
                    DataTable table = new DataTable();
                    foreach (PropertyDescriptor prop in properties)
                    {
                        table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
                    }
                    foreach (SceneUpdateRequest item in model.Scenes)
                    {
                        DataRow row = table.NewRow();
                        foreach (PropertyDescriptor prop in properties)
                        {
                            row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
                        }
                        table.Rows.Add(row);
                    }

                    cmd.Parameters.AddWithValue("@List", table);

                    cmd.ExecuteNonQuery();
                }
                conn.Close();
            }
            if (model.Scenes.Find(sce => sce.Id == null) != null)
            {
                SceneAddRequest add = new SceneAddRequest();
                add = model.Scenes.Find(sce => sce.Id == null);
                id  = SceneService.Insert(add);
            }
            return(id);
        }