using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using MvcWriter.Models;

namespace MvcWriter.Services
{
    public class WebAPIController : ApiController
    {
        public List<WriterModel> GetWriterData()
        {            
            return NDatabaseIO.WriterData.ReadWriters();
        }

        public HttpResponseMessage UpdateWriterData(WriterModel model)
        {            
            var success = NDatabaseIO.WriterData.UpdateWriter(model.writerID, model);
            if (success)
            {
                return Request.CreateResponse(HttpStatusCode.OK, model);
            }
            return Request.CreateResponse(HttpStatusCode.BadRequest);     
        }

        public HttpResponseMessage POSTAddWriterData(WriterModel model)
        {
            var success = NDatabaseIO.WriterData.CreateWriter(model);
            if (success)
            {
                return Request.CreateResponse(HttpStatusCode.OK, model);
            }
            return Request.CreateResponse(HttpStatusCode.BadRequest);            
        }
    }
}