public partial class Konular { public string KonuBasligi { get; set; } public string KonuIcerigi { get; set; } }
[Route("api/AjaxAPI/KonuListem")] [HttpPost] public class AjaxAPIController : ApiController { [Route("api/AjaxAPI/GetItems")] [HttpPost] public List< Konular> KonuListem(KonuGetir k) { myEntities db = new myEntities(); return (from c in db.Konular where c.KonuBasligi.StartsWith(k.Icerik) //StartsWith ile Baslangic Karakterine Gore Filtreleme select c).ToList(); } }
[Route("api/AjaxAPI/KonuEkle")] [HttpPost] public class KonuEkle { public string KonuBasligi { get; set; } public string KonuIcerigi { get; set; } public DateTime KayitTarihi { get; set; } }
[Route("api/AjaxAPI/KonuEkle")] [HttpPost] public string KonuEkle(KonuEkle k) { myEntities db = new myEntities(); Konular _k = new Konular(); _k.KonuBasligi = k.KonuBasligi; _k.KonuIcerigi = k.KonuIcerigi; _k.KayitTarihi = DateTime.Now; db.Konular.Add(_k); db.SaveChanges(); return ("Ekleme Başarılı."); }
[Route("api/AjaxAPI/SifreUret")] [HttpPost] public string SifreUret(KullaniciSifre SifreK) { string Sifre = DateTime.Now.DayOfWeek.ToString(); string SaltDegeri = Crypto.GenerateSalt(); return SaltDegeri; }
public class KonuGetir { public string Icerik { get; set; } }
public class AjaxAPIController : ApiController { [Route("api/AjaxAPI/GetItems")] [HttpPost] public List< Konular> KonuListem(KonuGetir k) { myEntities entities = new myEntities(); return (from c in entities.Konular where c.KonuBasligi.StartsWith(k.Icerik) //StartsWith ile Baslangic Karakterine Gore Filtreleme select c).ToList(); } }
< script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js">< script> < script type="text/javascript"> var app = angular.module('MyApp', []) app.controller('MyController', function ($scope, $http, $window) { $scope.IsVisible = false; $scope.Search = function () { var konular = '{Icerik: "' + $scope.Prefix + '" }'; var post = $http({ method: "POST", url: "/api/AjaxAPI/KonuListem", dataType: 'json', data: customer, headers: { "Content-Type": "application/json" } }); post.success(function (data, status) { $scope.Konularim = data; $scope.IsVisible = true; }); post.error(function (data, status) { $window.alert(data.Message); }); } }); script> < div ng-app="MyApp" ng-controller="MyController"> Konu : < input type="text" ng-model="Prefix" /> < input type="button" value="Ara" ng-click="Search()" /> < hr /> < ul ng-repeat="m in Konularim"> < li>< a href="/Home/{{m.KonuBasligi}}">{{m.KonuBasligi}} {{"/" + m.KonuIcerigi}} < /a>< /li> < /ul> < /div>
< input name="ad" type="text" id="text" placeholder="Deger Giriniz"/> < br /> < input name="btnGonder" type="submit" id="btnGonder" value="Gönder" />
< script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> < script> $(document).ready(function () { $('#btnGonder').click(function () { $.post('~/Home/Kayit/', { myText: text }, function (yeniKayit) { alert("Kayit Eklendi"); }); }); }); < /script>