public bool Add(string title, string description, string userName, string token, string base64 = "", string fileName = "") { if (token != WebConfigurationManager.AppSettings["token"]) { return(false); } const bool isActive = false; var filePath = ""; if (!string.IsNullOrEmpty(base64)) { try { var path = Path.GetExtension(fileName); filePath = AdoFunc.GetUniqueKey(60) + path; var serverPath = Server.MapPath("images/" + filePath); using (var fs = new FileStream(serverPath, FileMode.Create)) { using (var bw = new BinaryWriter(fs)) { byte[] data = Convert.FromBase64String(base64); bw.Write(data); bw.Close(); } } } catch (Exception ex) { return(false); } } return(AdoFunc.Cmd(@"insert into News (Title, Description, UserName, IsActive, FilePath) values ('" + title.ClearSql() + "','" + description.ClearSql() + "','" + userName.ClearSql() + "','" + isActive + "','" + filePath.ClearSql() + "')") > 0); }
protected void rptNews_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e) { if (e.CommandName == "Publish") { var data = e.CommandArgument.ToString().ClearSql().Split(','); var id = Convert.ToInt32(data[0]); var status = data[1] == "True" ? 0 : 1; var result = AdoFunc.Cmd("update News set IsActive=" + status + " where NewsId=" + id); if (result > 0) { lblInfo.Text = status == 0 ? "Haber başarılı bir şekilde yayından kaldırıldı" : "Haber başarılı bir şekilde yayınlandı.";; List(); } else { lblInfo.Text = "Bir hata oluştu lütfen daha sonra tekrar deneyiniz."; } lblInfo.Visible = true; } }