TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
2.1k
480.8k
How to expose API endpoints in C# WebServices?
Oct 13 2020 7:29 AM
// Model
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Runtime.Serialization;
using
System.Web;
namespace
CoinJarAPI.Models
{
[DataContract]
public
class
CoinJarModel
{
[DataMember(Name =
"volume"
)]
public
decimal
Volume {
get
;
set
; }
[DataMember(Name =
"amount"
)]
public
decimal
Amount {
get
;
set
; }
[DataMember(Name =
"getTotalAmount"
)]
public
decimal
GetTotalAmount {
get
;
set
; }
}
}
// Controller
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Net;
using
System.Net.Http;
using
System.Web.Http;
using
CoinJarAPI.Models;
namespace
CoinJarAPI.Controllers
{
public
class
CoinJarController : ApiController
{
// GET: api/CoinJar
public
IEnumerable<CoinJarModel> Get()
{
var coinJarList =
new
List<CoinJarModel>();
for
(
int
i = 0; i < 10; i++)
{
var coinjarModel =
new
CoinJarModel
{
// volume, Amount, GetTotalAmount.
};
}
return
coinJarList;
}
// GET: api/CoinJar/5
public
string
Get(
int
id)
{
return
"value"
;
}
}
}
// Interface
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
namespace
CoinJarAPI.Interface
{
interface
ICoinJar
{
void
AddCoin(ICoin coin);
decimal
GetTotalAmount();
void
Reset();
}
public
interface
ICoin
{
decimal
Amount {
get
;
set
; }
decimal
Volume {
get
;
set
; }
}
}
Hi Team
I want to expose 3 endpoints that will do this following and this is what i have currently, question where do i implement these endpoints? Controller or Interface, do i have create a Model? Need some advice
Add a coin
Get the total amount of coins
Reset the coins
Reply
Answers (
2
)
How to write the interface code as shown in the asp.net language?
Full Calendar events in asp.net mvc 5