Skip to content

Instantly share code, notes, and snippets.

@mahmut-gundogdu
Created July 18, 2014 13:49
Show Gist options
  • Save mahmut-gundogdu/0bcae6dc835a21c1d601 to your computer and use it in GitHub Desktop.
Save mahmut-gundogdu/0bcae6dc835a21c1d601 to your computer and use it in GitHub Desktop.
Nosql biggy ile asp.net de sabit verilerin ve uygulama ayarlarının saklanması. http://mahmutgundogdu.azurewebsites.net/?p=242
using Biggy;
using Biggy.JSON;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace AYarlar
{
public class Firma
{
public string Adi { get; set; }
public string Telefon { get; set; }
public string Eposta { get; set; }
}
public class Ayarlar
{
public Ayarlar()
{
IBiggyStore<Firma> ayarlar = new JsonStore<Firma>(dbPath: HttpRuntime.AppDomainAppPath);
//Her durumda 1 tane ayar olması için single aldım.
this.firma= ayarlar.Load().SingleOrDefault();
}
public Firma firma { get; set; }
public void Kaydet()
{
IBiggyStore<Firma> ayarlar = new JsonStore<Firma>(dbPath: HttpRuntime.AppDomainAppPath);
var x = ayarlar.Load().SingleOrDefault();
if (x != null)
{
x = this.firma;
ayarlar.Update(x);
}
else
{
ayarlar.Add(this.firma);
}
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AYarlar.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<% AYarlar.Ayarlar s = new AYarlar.Ayarlar();
if (s.firma != null)
{%>
<h3><%=s.firma.Adi %> </h3>
<p>
Telefon: <%=s.firma.Telefon %>
<br />
Eposta <%=s.firma.Eposta %>
</p>
<%} else { %>
<div>
SirketAdi:<asp:TextBox runat="server" ID="txtSirketAdi" /><br />
Telefon::<asp:TextBox runat="server" ID="txtTel" /><br />
Eposta:<asp:TextBox runat="server" ID="txtEposta" /><br />
<asp:Button Text="Kaydet" ID="btnKaydet" OnClick="btnKaydet_Click" runat="server" />
</div>
<% } %>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AYarlar
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnKaydet_Click(object sender, EventArgs e)
{
Firma s = new Firma();
Ayarlar data = new Ayarlar();
s.Eposta = txtEposta.Text;
s.Telefon = txtTel.Text;
s.Adi = txtSirketAdi.Text;
data.firma = s;
data.Kaydet();//bu fonksiyon ile datamız kaydedildi.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment