Ejemplo n.º 1
0
    public static ReturnObject DoAction(string employee_id, string leave_data)
    {
        leave_assign page_object    = new leave_assign();
        DBConnection db_connection  = new DBConnection();
        ReturnObject return_object  = new ReturnObject();
        JArray       processed_data = new JArray();

        string leave_code = string.Empty, response_status = string.Empty;
        double leave_balance = 0.0, max_leave = 0.0, leave_applied = 0.0;

        try
        {
            processed_data = JArray.Parse(leave_data);

            for (int i = 0; i < processed_data.Count; i++)
            {
                leave_code    = Convert.ToString(processed_data[i]["leave_code"]);
                max_leave     = Convert.ToDouble(processed_data[i]["max_leave"]);
                leave_applied = Convert.ToDouble(processed_data[i]["leave_applied"]);
                leave_balance = Convert.ToDouble(processed_data[i]["leave_balance"]);

                if (leave_applied <= max_leave)
                {
                    response_status += leave_code + " " + page_object.LeaveAction(employee_id, leave_code, max_leave, leave_applied, leave_balance);
                }
            }

            if (response_status == "")
            {
                response_status = "Leaves assigned successfully!";
            }

            return_object.status      = "success";
            return_object.return_data = JsonConvert.SerializeObject(response_status, Formatting.Indented);
        }
        catch (Exception ex)
        {
            Logger.LogException(ex, page, "GET_OTHER_DATA");

            return_object.status      = "error";
            return_object.return_data = "An error occurred while save Assigned Leaves data. Please try again. If the error persists, please contact Support.";
        }

        return(return_object);
    }