1.developerfusion
2.dotnetspider
3.telerik
4.carlosag
5.sharpdevelop
6.all4dotnet
Tidak hanya convert vb dan c#, tetapi juga ke bahasa lainnya
Media Smart Software adalah konsultan IT sekaligus penyedia software komputer.
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; namespace MyBook.Controllers { public class ValuesController : ApiController { // GET api/values public IEnumerable<string> Get() { return new string[] { "value1", "value2" }; } // GET api/values/5 public string Get(int id) { return "value"; } // POST api/values public void Post([FromBody]string value) { } // PUT api/values/5 public void Put(int id, [FromBody]string value) { } // DELETE api/values/5 public void Delete(int id) { } } }
config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace MyBook.Controllers.Models { public class Book { public string ISBN { set; get; } public string Title { set; get; } public long pages { set; get; } public string publisher { set; get; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; using MyBook.Controllers.Models; namespace MyBook.Controllers { public class BookController : ApiController { // GET api/<controller> public static List<Book> MyBook=new List<Book>(); public IEnumerable<Book> Get() { List<Book> All = new List<Book>() { new Book(){ ISBN="1239482", pages=500, publisher="Gramedia", Title="20 Hours Coding C#" }, new Book(){ ISBN="09463474", pages=20, publisher="Erlangga", Title="You see sharp by c#" }, }; if (MyBook.Count == 0) { MyBook = All; } return MyBook; } // GET api/<controller>/5 public Book Get(string ISBN) { var book = (from query in MyBook where query.ISBN == ISBN select new Book() { ISBN=query.ISBN, publisher=query.publisher, pages=query.pages, Title=query.Title }).FirstOrDefault(); return book; } // POST api/<controller> [HttpPost] public void Post(Book data) { if (data != null) { MyBook.Add(data); } } [HttpPost] // PUT api/<controller>/5 public void Put(String ISBN,Book newData) { int index = MyBook.FindIndex(p => p.ISBN == ISBN); MyBook.RemoveAt(index); MyBook.Add(newData); } // DELETE api/<controller>/5 [HttpPost] public void Delete(String ISBN) { MyBook.RemoveAll(p => p.ISBN == ISBN); } } }Code diatas dilengkapi dengan operasi CRUD untuk Buku.
<sectionclass="content-wrapper main-content clear-fix">
<table>
<tr>
<td>ISBN</td>
<td>:</td>
<td><inputtype="text"id="txtISBN"></td>
</tr>
<tr>
<td>Pages</td>
<td>:</td>
<td><inputtype="text"id="txtPages"></td>
</tr>
<tr>
<td>Title</td>
<td>:</td>
<td><inputtype="text"id="txtTitle"></td>
</tr>
<tr>
<td>Publisher</td>
<td>:</td>
<td><inputtype="text"id="txtPublisher"></td>
</tr>
<tr>
<td></td>
<td></td>
<td><buttonid="save"onclick="Save()">Save</button></td>
</tr>
</table>
</section>
</div>
<script>
function Save() {
jQuery.support.cors = true;
var _isbn = $("#txtISBN").val();
var _page = $("#txtPages").val();
var _publisher = $("#txtPublisher").val();
var _title = $("#txtTitle").val();
var book = {
ISBN :_isbn,
Title: _title,
pages:_page,
publisher:_publisher
};
$.ajax({
url: '../api/book',
type: 'POST',
data: JSON.stringify(book),
contentType: 'application/json; charset=utf-8',
success: function (data) {
alert("Successful Add");
},
error: function (data) {
alert("UnSuccessful");
}
});
}
</script>