using ResourcesManager.Interfaces;
using ResourcesManager.Models;
using ResourcesManager.Repositories;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace ResourcesManager.Handlers
{
    public class ResourceRepository : BaseRepository, IResourceRepository
    {
        public ResourceRepository(ApplicationDbContext context): base(context){}

        public bool DeleteResouce(int id)
        {
            var resource = Context.Resources.Find(id);
            Context.Resources.Remove(resource);
            Save();
            return true;
        }

        public Resource GetResourceByID(int id)
        {
            return Context.Resources.Find(id);
        }

        public IEnumerable<Resource> GetResouces()
        {
            return Context.Resources;
        }

        public bool InsertResouce(Resource resource)
        {
            Context.Resources.Add(resource);
            Save();
            return true;
        }

        public bool UpdateResouce(Resource resouce)
        {
            Context.Entry(resouce).State = EntityState.Modified;
            Save();
            return true;
        }
    }
}