public int Delete()
        {
            Absence absence = new Absence();
            int     rows    = 0;

            using (StreamReader sr = new StreamReader(Request.Body))
            {
                absence = JsonConvert.DeserializeObject <Absence>(sr.ReadToEnd());
            }
            if (absence != null)
            {
                string query = "DELETE FROM AbsenceTable WHERE Id=@Id;";
                using (SqlConnection conn = new SqlConnection(Connection.ConnString))
                {
                    try
                    {
                        conn.Open();
                        rows = conn.Execute(query, absence);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex);
                        rows = -1;
                    }
                }
            }
            if (rows > 0)
            {
                RosterController.UpdateAbsence(absence.EmployeeId, -absence.Hours, RosterController.GetWeek(absence.StartDate));
            }
            return(rows);
        }
        public int Create()
        {
            Absence absence = new Absence();
            int     rows    = 0;

            using (StreamReader sr = new StreamReader(Request.Body))
            {
                absence = JsonConvert.DeserializeObject <Absence>(sr.ReadToEnd());
            }
            if (absence != null)
            {
                string query = "IF NOT EXISTS (SELECT * FROM AbsenceTable WHERE EmployeeId=@EmployeeId AND StartDate=@StartDate) " +
                               "INSERT INTO AbsenceTable (EmployeeId, EmployeeName, Type, StartDate, EndDate, Hours)" +
                               "VALUES (@EmployeeId, @EmployeeName, @Type, @StartDate, @EndDate, @Hours);";
                using (SqlConnection conn = new SqlConnection(Connection.ConnString))
                {
                    try
                    {
                        conn.Open();
                        rows = conn.Execute(query, absence);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex);
                        rows = -1;
                    }
                }
            }
            if (rows > 0)
            {
                RosterController.UpdateAbsence(absence.EmployeeId, absence.Hours, RosterController.GetWeek(absence.StartDate));
            }
            return(rows);
        }
        public int Update()
        {
            Absence before;
            Absence after;
            int     rows = 0;

            using (StreamReader sr = new StreamReader(Request.Body))
            {
                List <Absence> absences = JsonConvert.DeserializeObject <List <Absence> >(sr.ReadToEnd());
                before = absences[0];
                after  = absences[1];
            }
            if (after != null)
            {
                string query = "UPDATE AbsenceTable" +
                               " SET Type=@Type, EndDate=@EndDate, Hours=@Hours WHERE Id=@Id;";
                using (SqlConnection conn = new SqlConnection(Connection.ConnString))
                {
                    try
                    {
                        conn.Open();
                        rows = conn.Execute(query, after);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex);
                        rows = -1;
                    }
                }
            }
            if (rows > 0)
            {
                double difference = after.Hours - before.Hours;
                RosterController.UpdateAbsence(after.EmployeeId, difference, RosterController.GetWeek(after.StartDate));
            }
            return(rows);
        }