using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EnvigoHiring.Models.Department
{
    public class Department
    {
        public int DepartmentID { get; set; }
        [Required(ErrorMessage = "Enter Department Name!")]
        public string DepartmentName { get; set; }
        public string MessageType { get; set; }
        public string lblMessage { get; set; }
        public DataTable ListData { get; set; }

        DataLayer obj = DataLayer.Instance;

        public DataTable EditData()
        {
            string query = string.Format(@"SELECT * from tblMasterDepartment where DepartmentID={0}", DepartmentID);
            return obj.SelectDatatable(query);
        }
        public DataTable getdata()
        {
            string query = string.Format(@"SELECT  * from tblMasterDepartment order by Departmentname asc");
            return obj.SelectDatatable(query);
        }
        public bool CheckDepartment(int DesID)
        {
            string Query = "";
            if (DesID == 0)
            {
                Query = string.Format(@"select Departmentname from tblMasterDepartment where Departmentname= '" + HttpUtility.HtmlEncode(DepartmentName.Trim().ToString()) + "'");
            }
            else
            {
                Query = string.Format(@"select Departmentname from tblMasterDepartment where Departmentname= '" + HttpUtility.HtmlEncode(DepartmentName.Trim().ToString()) + "' and DepartmentID !=" + DepartmentID + "");
            }
            DataTable dt = obj.SelectDatatable(Query);
            if (dt.Rows.Count > 0) { return true; } else { return false; }
        }
        public int add()
        {
            string query = string.Format(@"insert into tblMasterDepartment (Departmentname) values('" + HttpUtility.HtmlEncode(DepartmentName.Trim().ToString()) + "')");
            int i = obj.ExecuteNonQuery(query);
            return i;

        }

        public int edit()
        {
            string query = string.Format(@"update tblMasterDepartment set Departmentname ='" + HttpUtility.HtmlEncode(DepartmentName.Trim().ToString()) + "' where DepartmentID=" + DepartmentID);
            int i = obj.ExecuteNonQuery(query);
            return i;

        }

    }

}