public object UpdateProgramme([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 programmeId = int.Parse(Request.Form.First(c => c.Key == "programmeId").Value); 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 fileName = ""; var files = Request.Form.Files; if (files.Count != 0) { var file = files[0]; 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}"; using (var fs = System.IO.File.Create(imagePath)) { file.CopyTo(fs); fs.Flush(); } } var cm = new UpdateProgrammeModel { ProgrammeId = programmeId, ProgrammeName = programmeName, Duration = duration, Profile = profile, Tags = tags }; var re = ProgrammeServer.UpdateAndPlayBill(cm, fileName); return(re); } catch (Exception e) { return(new { result = e.HResult, msg = e.Message }); } }
///<summary> /// 更新剧目 /// </summary> /// <param name="cm">更新剧目各种信息</param> /// <param name="filePath">图片路径</param> /// <returns>更新结果</returns> public static object UpdateAndPlayBill(UpdateProgrammeModel cm, string filePath) { using (var con = new SqlConnection(Server.SqlConString)) { con.Open(); var sqlCom = new SqlCommand("sp_UpdateProgramme", con) { CommandType = CommandType.StoredProcedure }; sqlCom.Parameters.AddRange(new [] { new SqlParameter { ParameterName = "@programmeId", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.Int, Value = cm.ProgrammeId }, new SqlParameter { ParameterName = "@programmeName", Direction = ParameterDirection.Input, Size = 50, SqlDbType = SqlDbType.NVarChar, Value = cm.ProgrammeName }, new SqlParameter { ParameterName = "@programmeDuration", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.Int, Value = cm.Duration }, new SqlParameter { ParameterName = "@programmeTags", Direction = ParameterDirection.Input, Size = 20, SqlDbType = SqlDbType.NVarChar, Value = cm.Tags }, new SqlParameter { ParameterName = "@programmeProfile", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.Text, Value = cm.Profile }, new SqlParameter { ParameterName = "@programmeImagePath", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.VarChar, Size = 100, Value = filePath }, 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 }); } }