Skip to content
Snippets Groups Projects
Select Git revision
  • a54fa5527ed64c9532a19d5c9647e3574f30f7cc
  • master default
  • dev
3 results

FightController.cs

Blame
  • user avatar
    Clément authored
    a54fa552
    History
    FightController.cs 1.82 KiB
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using WebApiGOT.Models;
    using BusinessLayer;
    using System.Net;
    using System.Net.Http;
    using System.Web.Http;
    using EntitiesLayer;
    
    namespace WebApiGOT.Controllers
    {
        public class FightController : ApiController
        {
            // GET: api/Fight
            public List<FightDTO> GetAllFight()
            {
                List<FightDTO> list = new List<FightDTO>();
                BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
                foreach (EntitiesLayer.Fight fight in busi.FightsList())
                {
                    list.Add(new FightDTO(fight));
                }
                return list;
            }
    
            // GET: api/Fight/2
            public FightDTO Get(int id)
            {
                BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
                return new FightDTO(busi.getFightById(id));
            }
    
            // POST: api/Fight
            public void PostAddFight(FightDTO f)
            {
                House challenger1 = new House(f.Challenger1.ID, f.Challenger1.Name, f.Challenger1.NbUnits);
                House challenger2 = new House(f.Challenger2.ID, f.Challenger2.Name, f.Challenger2.NbUnits);
                War war = new War(f.War.ID,f.War.Name);
                Fight fight = new Fight(f.Name, challenger1, challenger2, war);
                BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
                busi.addFight(fight);
            }
    
            // PUT: api/Fight/2
            public void Put(int id, [FromBody]string value)
            {
            }
    
            // DELETE: api/Fight/2
            public void DeleteFight(int id)
            {
                BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
                busi.deleteFight(id);
            }
        }
    }