Ejemplo n.º 1
0
        public override Task <int> AddOrModifyDto(_80sEntertainmentTVShowsDAO dao, AddOrModify action)
        {
            // Order is VERY IMPORTANT. It must exactly follow the order of the parameters of the
            //  stored procedure it will be using in the database. Do not include the output
            //  parameter in the stored procedure. The base method will already take account of it.

            // Also, don't include the primary id of the table in the parameterList list, val will be used
            //  and it will be the first one inserted in the list, so please make sure the primary id
            //  parameter is the first one in the stored procedure.
            var theList = new List <object>
            {
                dao.ShowName,
                dao.YearId,
                dao.GenreId,
                dao.EpisodeName,
                dao.SeasonNumber,
                dao.EpisodeNumber,
                dao.Ent80sId
            };

            return(AddOrModifyDtoAsync(action, dao.Id, theList));
        }
        protected async Task <int> AddOrModifyDtoAsync(AddOrModify action, int primaryId, List <object> parametersList)
        {
            // Order is VERY IMPORTANT. It must exactly follow the order of the parameters of the
            //  stored procedure it will be using in the database. Do not include the output
            //  parameter in the stored procedure. The base method will already take account of it.

            // Also, don't include the primary id of the table in the parameterList list,
            //  There's a parameter for that already, primaryID.
            //  and it will be the first one inserted in the list, so please make sure the primary id
            //  parameter is the first one in the stored procedure.

            var val = action == AddOrModify.Add ? -1 : primaryId;

            SqlParameter output = new SqlParameter
            {
                ParameterName = "@output",
                Direction     = System.Data.ParameterDirection.Output,
                SqlDbType     = System.Data.SqlDbType.Int
            };

            var paramList = new List <SqlParameter> {
                new SqlParameter("@p0", val)
            };

            for (var i = 1; i < paramList.Count; i++)
            {
                paramList.Add(new SqlParameter("@p" + i, Func.GetDbNullValue(parametersList[i])));
            }

            // Stored Procedure's output should be the last parameter in the SQL stored procedure.
            paramList.Add(output);

            var sqlParams = string.Join(",", paramList.Select(x => x.ParameterName).ToList()) + " out";

            int t = await DbContext.Database.ExecuteSqlCommandAsync(Application.DatabaseSchema + AddModStoredProc + " " + sqlParams, paramList);

            return((int)output.Value);
        }
Ejemplo n.º 3
0
 public abstract override Task <int> AddOrModifyDto(T dao, AddOrModify action);