25 Nisan 2016 Pazartesi

ASP.NET MVC'de Search İşlemi -1

Öncelikle View’da form oluşturmamız gerek. Çünkü arama şartlarını bu form ile Controller’a ileteceğiz.


@using (Html.BeginForm("Index", "Home", FormMethod.Get))
{}

Burada yazdığımız “Index” = Action
“Home”  = Controller’ın adı
Formmethod.Get ise; bu form ile yaptığımız işlemin bir “Get” operasyonu olduğunu gösteriyor.
Arama şartlarını (Kişiye göre ara / Türe göre ara) Radio Buttonlar aracılığıyla seçeceğiz.

@Html.RadioButton("SearchBy", "SearchByBook", true); <text> İsme Göre</text>
    @Html.RadioButton("SearchBy", "SearchByRating") <text> Puana Göre</text>
    @Html.RadioButton("SearchBy", "SearchByAuthor") <text> Yazara Göre</text>
    @Html.RadioButton("SearchBy", "SearchByGender") <text> Türe Göre</text>

RadioButton’un aldığı ilk parametre görüldüğü gibi “SearchBy” olarak girildi.  Yazdığımız “SearchBy”, RadioButton’un ismidir. Bu ismi, Controller kısmında kullanacağız.

RadioButton’un ikinci parametresi de “SearchByBook”. Bu parametre ile, kullanıcının neye göre arama yaptığını (isim,tür,puan vb) anlamış olacağız. Bu arada üçüncü parametre olan “true” ise, bu Radiobutton’un otomatik olarak seçili gelmesini sağlayacak.
Ve bir TextBox ve  “Ara” isminde bir button oluşturalım ve kullanıcının yazdığı veriyi Server’a gönderelim.

@Html.TextBox("SearchTerm")

    <input type="submit"
           value="Ara!" class="buttonSearch" />

Görüleceği üzere; TextBox’un ismi “SearchTerm” olarak girilmiştir. Bu ismi kullanarak, Controller kısmında, kullanıcının TextBox’a yazdığı ve gönderdiği veriyi elde etmiş olacağız. Şimdi Controller kısmına geçelim.

   public ActionResult Index(string searchBy, string searchTerm)
{
if (searchBy == "SearchByBook")
{
Return View(_sampleContext.Books.Where(b => b.BookName.StartsWith(SearchTerm)).ToList)

….

Şimdi ise View ve Controller’da tam olarak ne olup bittiğini anlayalım:

@Html.RadioButton("SearchBy", "SearchByBook", true);

Bu radiobutton un adı SearchBy, değeri ise SearchByBook’tur.
Controller kısmında:

public ActionResult Index(string searchBy, string searchTerm)

String SearchBy yazmıştık. Bu SearchBy parametresiyle; ismi SearchBy olan buttonlarımızın “Value’sini alıyoruz” Örneğin bi üstteki radiobutton’un değeri SearchByBook idi.. Yani kullanıcı eğer bu radiobutton’u seçer ise şayet; biz controller’daki searchBy parametremize SearcyByBook değerini atamış oluruz. SearchBy parametresinde gerçekleşen işlem budur.
String SearchTerm ile ise; kullanıcının TextBox’a yazdığı veriyi çekmiş olduk..

@Html.TextBox("SearchTerm")

Burada gerçekleşen işlem de aynı mantık ile ilerliyor. TextBox’un adını bildiğimiz üzere “SearchTerm” olarak girmiştik. Dolayısıyla kullanıcının TextBox’a yazmış olacağı herhangi bir kelime veya harfi; Controllerda bulunan String SearchTerm parametresine atamış olacağız.

public ActionResult Index(string searchBy, string searchTerm)

Yani ne yapmış olduk? Kişinin neye göre arama yapacağını (türe göre mi, isme göre mi, yoksa puana göre mi) SearchBy parametresine atmış olduk è View kısmında radiobuttonların ismi SearcBy idi ve bu ismi kullanarak seçilen RadioButton’un değerine ulaşmış olduk.

SearchTerm parametresine ise, yine aynı şekilde kullanıcının, SearchTerm isimli TextBox’a yazmış olduğu veriyi, yine Controller’da bulunan String SearchTerm parametresine atamış olduk.

Ve bu parametrelere atanmış olan verileri elde ederek; kullanıcının istediği şekilde olan arama sonuçlarını listeleterek kullanıcıya sunmuş olduk.

Return View(_sampleContext.Books.Where(b => b.BookName.StartsWith(SearchTerm)).ToList)

Kodların derlenmiş hali:

VIEW:
@using (Html.BeginForm("Index", "Home", FormMethod.Get))
{
    <b>Ara: &nbsp&nbsp</b>
    @Html.RadioButton("SearchBy", "SearchByBook", true); <text> İsme Göre</text>
    @Html.RadioButton("SearchBy", "SearchByRating") <text> Puana Göre</text>
    @Html.RadioButton("SearchBy", "SearchByAuthor") <text> Yazara Göre</text>
    @Html.RadioButton("SearchBy", "SearchByGender") <text> Türe Göre</text>
    <br />
    @Html.TextBox("SearchTerm")
    <input type="submit"
           value="Ara!" class="buttonSearch" />
}


CONTROLLER:
public ActionResult Index(string searchBy, string searchTerm) 
        {
            if (searchBy == "SearchByBook")
            {
                return View( "abc", _myLibraryContext.Books.Where(x=>x.BookName.StartsWith(searchTerm)).ToList());
            }
            if (searchBy == "SearchByRating")
            {
                return View("abc", _myLibraryContext.Books.Where(n => n.Rating.ToString() == searchTerm));
            }
            else
            {
                return View("abc", _myLibraryContext.Books.ToList());
            }
       }



7 Mart 2016 Pazartesi

Jquery'de Syntax

$(this).hide()    - bahsi geçen elementi gizler.

$("p").hide()     - <p> elementlerinin tümünü gizler.

$(".test").hide() - class="text" olan elementleri gizler.

$("#test").hide() - id="test" olan elementi gizler.

5 Şubat 2016 Cuma

Diğer

Variables

Creating a variable reserves a memory location, or a space in memory, for storing values.
To use a variable, it must first be declared by specifying the name and data type.
A variable name, also called an identifier, can contain letters, numbers and the underscore character (_) and must start with a letter or underscore. 
For example, firstName and lastName are good descriptive variable names.

Double vs Float

As the name implies,double has 2x the precision of float. In general a double has 15 decimal digits of precision, while float has 7.

IDE

To create a C# program, you need to install an integrated development environment (IDE) with coding and debugging tools. For example: Visual Studio Community Edition.

Assignment Operators (=) / Postfix & Prefix Operators

The = assignment operator assigns the value on the right side of the operator to the variable on the left side. 
int x = 42;
-
Postfix example:

            int x = 3;
            int y = x++;
            // x is 4, y is 3

The prefix example increments the value of x, and then assigns it to y.
The postfix example assigns the value of x to y, and then increments x.

11 Aralık 2015 Cuma

Ruby'de Array Manipulations

puts"Ornek I"

a = [1, 2, 3]
b = [4, 5]

toplam = a + b
puts toplam  #sonuç: [1, 2, 3, 4, 5]


puts"Ornek II"

c = [1, 2, 3, 4, 5, 6, 7, 8]
d = [2, 4, 5]

res = c - d
puts res #sonuç: [1, 3, 6, 7, 8]

#Birinci array'da bulunan elementlerden, ikinci array'da bulunan elementleri çıkartma işlemi (bildiğimiz çıkarma işlemi şeklinde de düşünülebiliriz)


puts"Ornek III"

e = [1, 2, 3, 4]
f = [3, 4, 5, 6]

puts e & f #sonuç [3, 4]

#Birinci ve ikinci array'larda bulunan aynı elementleri yazdırma işlemi. (a VE b'de bulunan elementler..)


puts"Ornek IV"

g = [1, 3, 5, 7]
h = [2, 4, 6]

puts g | h #sonuç [1, 3, 5, 7, 2, 4, 6]

# g VEYA h'de bulunan elementleri yazdırma işlemi. (yani g'deki elementler +  h'deki elementler)


puts"Ornek V"

newArr = [1, 2, 3, 4]
res = newArr.reverse
puts newArr # [4, 3, 2, 1]

#elementleri ters döndürülmüş sırayla yazdırma.


puts"Ornek VI"

abc = [1, 2, 3]
puts abc.reverse!

#ters döndürülmüş array'ı yeni bir değişkene atmadan direkt olarak "puts" metodu içinde yazdırma

modifying list items with HTML / CSS

<head>
    <style>
        a{text-decoration:none; color:pink;}
        /*a:hover{background-color:white;}*/

        .customStyle:hover{
            background-color:gray;
            transition-duration:0.4s;
            color:red;
        }
       
        /*li span{color:red;}*/
  
        li span{width:600px;  text-indent:1em; display:inline-block;}
        li span:hover{color:black !important;}
       
ul {
    list-style: none;
    padding:3;
    margin:10;
}

li {
    padding-left: 5em;
    text-indent: -.em;
}

li:before {
    content: "• ";
    color: red; /* or whatever color you prefer */
}

li:hover:before{
    content:" ○";
    color:white ;
}

li:after{
    content:" •";
    color:green;
}

li:hover:after{
    content:" ○";
    color:white;
}
    </style>
</head>

<body style="background-color:#272822">
<ul>
    <a href=""><li class="customStyle"><span>Anasayfa</span></li></a>
    <a href=""><li class="customStyle"><span>Kitaplar</span></li></a>
    <a href=""><li class="customStyle"><span>Yazarlar</span></li></a>
</ul>
</body>