- // 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
Get() - {
- var coinJarList = new List
(); - 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; }
- }
- }
How to expose API endpoints in C# WebServices?
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
Guest UserPosted Oct 14, 2020, 6:30 AM
Junaid MuslaPosted Oct 14, 2020, 6:00 AM