public object CreateProgramme([FromServices] IHostingEnvironment env, [FromBody] CreateProgrammeModel cm)
        {
            try
            {
                var addr = Server.GetUserIp(Request.HttpContext);
                if (Server.IpHandle(addr) == 0)
                {
                    return(new[] { "your ip can't using our api , please contact administrator" });
                }

                var account = HttpContext.Session.GetString("user_account");

                if (account == null)
                {
                    return(new
                    {
                        result = 401,
                        msg = "not login"
                    });
                }

                var re = ProgrammeServer.CreateProgramme(cm);

                return(re);
            }
            catch (Exception e)
            {
                return(new
                {
                    result = e.HResult,
                    msg = e.Message
                });
            }
        }
Exemple #2
0
        public object CreateProgrammeAndPlayBill([FromServices] IHostingEnvironment env)
        {
            try
            {
//                var addr = Server.GetUserIp(Request.HttpContext);
//                if (Server.IpHandle(addr) == 0)
//                {
//                    return new[] {"your ip can't using our api , please contact administrator"};
//                }
//
                var account = HttpContext.Session.GetString("user_account");

                if (account == null)
                {
                    return(new
                    {
                        result = 401,
                        msg = "not login"
                    });
                }

                var files         = Request.Form.Files;
                var programmeName = Request.Form.First(c => c.Key == "programmeName").Value;
                var duration      = int.Parse(Request.Form.First(c => c.Key == "duration").Value);
                var profile       = Request.Form.First(c => c.Key == "profile").Value;
                var tags          = Request.Form.First(c => c.Key == "tags").Value;

                var file     = files[0];
                var fileName = DateTime.Now.Ticks + ContentDispositionHeaderValue
                               .Parse(file.ContentDisposition)
                               .FileName
                               .Trim().Value;
                //var imagePath = env.WebRootPath + @"./PlayBill/" +  DateTime.Now.Ticks + $@"{fileName}"; // in unix
                var imagePath = @"C:\\PlayBill\" + $@"{fileName}"; // in windows

                var cm = new CreateProgrammeModel
                {
                    ProgrammeName = programmeName,
                    Duration      = duration,
                    Profile       = profile,
                    Tags          = tags
                };

                using (var fs = System.IO.File.Create(imagePath))
                {
                    file.CopyTo(fs);
                    fs.Flush();
                }

                var re = ProgrammeServer.CreateProgrammeAndPlayBill(cm, fileName);

                return(re);
            }
            catch (Exception e)
            {
                return(new
                {
                    result = e.HResult,
                    msg = e.Message
                });
            }
        }
Exemple #3
0
        /// <summary>
        /// 新建一个剧目
        /// </summary>
        /// <param name="cm">新建剧目模型</param>
        /// <param name="imagePath">海报图片地址</param>
        /// <returns>新建结果</returns>
        public static object CreateProgrammeAndPlayBill(CreateProgrammeModel cm, string imagePath)
        {
            using (var con = new SqlConnection(Server.SqlConString))
            {
                con.Open();

                var sqlCom = new SqlCommand("sp_CreateProgrammeAndPlayBill", con)
                {
                    CommandType = CommandType.StoredProcedure
                };

                sqlCom.Parameters.AddRange(new[]
                {
                    new SqlParameter
                    {
                        ParameterName = "@proName",
                        Direction     = ParameterDirection.Input,
                        Size          = 50,
                        SqlDbType     = SqlDbType.NVarChar,
                        Value         = cm.ProgrammeName
                    },
                    new SqlParameter
                    {
                        ParameterName = "@duration",
                        Direction     = ParameterDirection.Input,
                        SqlDbType     = SqlDbType.Int,
                        Value         = cm.Duration
                    },
                    new SqlParameter
                    {
                        ParameterName = "@tags",
                        Direction     = ParameterDirection.Input,
                        Size          = 20,
                        SqlDbType     = SqlDbType.NVarChar,
                        Value         = cm.Tags
                    },
                    new SqlParameter
                    {
                        ParameterName = "@profile",
                        Direction     = ParameterDirection.Input,
                        SqlDbType     = SqlDbType.Text,
                        Value         = cm.Profile
                    },
                    new SqlParameter
                    {
                        ParameterName = "@imagePath",
                        Direction     = ParameterDirection.Input,
                        SqlDbType     = SqlDbType.VarChar,
                        Size          = 100,
                        Value         = imagePath
                    },
                    new SqlParameter
                    {
                        ParameterName = "@message",
                        Direction     = ParameterDirection.Output,
                        Size          = 30,
                        SqlDbType     = SqlDbType.VarChar
                    },
                    new SqlParameter
                    {
                        ParameterName = "@return",
                        Direction     = ParameterDirection.ReturnValue,
                        SqlDbType     = SqlDbType.Int
                    }
                });

                sqlCom.ExecuteNonQuery();

                return(new
                {
                    result = (int)sqlCom.Parameters["@return"].Value,
                    msg = (string)sqlCom.Parameters["@message"].Value
                });
            }
        }