Abraham Lukwesa

Abraham Lukwesa

  • NA
  • 15
  • 5.4k

How to search for a record in C# and AngularJs! or JavaScrip

Aug 11 2014 4:00 AM
Hi All,
 
Basically I am learning angular and C#.Net.. Which I am beginning to understand a little bit now.
 
I have crated a database in which I am adding records from the users input like so:
 
 
[HttpPost]
public HttpResponseMessage PostDs72(Persons p)
{
if (p == null)
return new HttpResponseMessage(HttpStatusCode.BadGateway);
PeopleContext db = new PeopleContext();
db.Persons.Add(p);
db.SaveChanges();
return new HttpResponseMessage(HttpStatusCode.Created);
}
 
 
n the code above is the c# code that is adding or creating a new person in the table Persons.

And in angular side of things this is what I have done: 
 
 
$scope.createPerson = function () {
$http({
method: 'POST',
url: '/api/Persons',
data: JSON.stringify($scope.newperson),
headers: { 'Content-Type': 'application/JSON' }
}).success(function (data) {
$scope.status = " Saved";
Getinfo();
}).error(function (error) {
$scope.status = 'Unabale to save ' + error.message;
});
};
 
this is the angular that code that is creating a new person. or function creating a new person

and in my HTML this is what I have done 
 
 
<input type="text" name="FirsName" data-ng-model="newperson.FirstName" placeholder="Enter First Name" required />
<input type="text" name="LastName" data-ng-model="newperson.Last" placeholder="Enter Last Name" required />
<input class="search" type="button" value="Add Person" data-ng-show="DisplaySave" data-ng-click="createPerson()"
 
 
And that is how I am adding people onto my database.

Now I am stuck! How do I go on in about search for record by their last name provided in a search textbox? can some one plsease help?

If this was windows forms I would code something like
 
SELECT * FROM Persons WHERE LastName = '"textbox1.text"'
 
 now ofcourse this is not winsforms but is there anyone that can help?

Thank you
 
 
 
 
 

Answers (3)