using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UmlApp.Models;

namespace UmlApp.Controllers
{
    public class UmlTaskController : Controller
    {
        UmlTaskDataContext _db = new UmlTaskDataContext();

        public ActionResult Index()
        {
            var umlTasks = _db.UmlTasks.ToList();
            return View(umlTasks);
        }

        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(UmlTask umlTask)
        {
            if (ModelState.IsValid)
            {
                _db.UmlTasks.Add(umlTask);
                _db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(umlTask);
        }

        public ActionResult UmlTask(int id)
        {
            var umlTask = _db.UmlTasks.Find(id);
            return View(umlTask);
        }

        public ActionResult Search(string searchBy, string search)
        {
            if (searchBy == "TagComplexity")
            {
                return View(_db.UmlTasks.Where(x => x.TagComplexity == search).ToList());
            }
            else if (searchBy == "TagRelationshipType")
            {
                return View(_db.UmlTasks.Where(x => x.TagRelationshipType == search).ToList());
            }
            else if (searchBy == "TagDiagramType")
            {
                return View(_db.UmlTasks.Where(x => x.TagDiagramType == search).ToList());
            }
            else
            {
                return View(_db.UmlTasks.Where(x => x.TagTaskType == search).ToList());
            }
        }
    }
}
