Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Team

I am struggling to expose 3 endpoints, because i dont know if need to implement them on the controller. These 3 endpoints must Add a coin.
Get the total amount of coins.
Reset the coins.

What I have tried:

C#
//Interface
<pre>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; }
    }
}


//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";
        }

    }
}

// 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; }
    }
}
Posted
Comments
ZurdoDev 13-Oct-20 10:00am    
I do not understand your question.
gcogco10 13-Oct-20 10:05am    
Zurdo what i meant is to how if you have an interface or controller consume 3 endpoints namely Add a coin, Get the total amount of coins, Reset coin. But it must first accept the latest coinage and volume 0f 42 fluids ounces. counter to keep track of total amount of money collected, reset bac to $0.00
lmoelleb 16-Oct-20 2:21am    
I think your use of terminology confuses quite a lot. Interfaces do not consume endpoints - they define things. Controllers exposes endpoints so that is indeed what you need here (and can also consume other endpoints defined elsewhere, but in your case this is not needed as far as I can see). You seem already having the start of "something", so what is the current problem exactly. Is it not doing what you expect? Is it doing what you expect so far, but you do not know how to proceed - in that case, what would be the next step you try to achieve?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900