private static Request LabourerRequestHander(Request req) { try { LabourerRequest lr = JsonConvert.DeserializeObject<LabourerRequest>(req.content); switch (req.purpose) { case Constants.New_Labourer: //inform the user MessageBoxResult mr = MessageBox.Show("A request has been made to register a new labourer proceed" ,"Labourer registration" , MessageBoxButton.YesNo); if(mr == MessageBoxResult.No) { return null; } Container c = new Container(); c._labourers = new labourers(); c._project_labour_allocation = new project_labour_allocation(); // insert a new value to the labourers table c._labourers.national_id = lr.national_id; c._labourers.labourer_id = lr.labourer_id; c._labourers.labourer_name = lr.labourer_name; c._labourers.labourer_contact = lr.labourer_contact; DB1 = new DBManager(); if (DB1.InsertValue(c, Constants.Labourers)) { MessageBox.Show("the labourer has been registered"); } // get the derived labourer id //allocate the registered labourer c._project_labour_allocation.project_id = lr.project_id; c._project_labour_allocation.labourer_id = DB1.GetLabourers("SELECT * FROM labourers WHERE national_id = '" + lr.national_id + "'").First().labourer_id; if (DB1.InsertValue(c, Constants.Project_Labour_Allocation)) { MessageBox.Show("the labourer has been registered to the project"); } break; case Constants.Labourers_List: // return the list of labourers to the foreman // DB1 = new DBManager(); c = new Container(); c._labourerslist = new List<labourers>(); c._labourerslist = DB1.GetLabourers("SELECT a.* FROM labourers a , project_labour_allocation b WHERE a.labourer_id = b.labourer_id AND b.project_id = " + lr.project_id + ""); Debug.WriteLine("SELECT a.* FROM labourers a , project_labour_allocation b WHERE a.labourer_id = b.labourer_id AND b.project_id = " + lr.project_id + ""); c._employeeslist = new List<employees>(); c._employeeslist = DB1.GetEmployees("SELECT a.* FROM employees a , project_employee_allocation b WHERE a.employee_id = b.employee_id AND b.project_id = " + lr.project_id + ""); Debug.WriteLine("SELECT a.* FROM employees a , project_employee_allocation b WHERE a.employee_id = b.employee_id AND b.project_id = " + lr.project_id + ""); //c._employees_list = DB1.GetLabourers() req.content = JsonConvert.SerializeObject(c); req.category = Constants.Labourers; req.purpose = Constants.Labourers_List; break; case Constants.Submit_Work_Day: DB1 = new DBManager(); c = JsonConvert.DeserializeObject<Container>(req.content); foreach (labourers labour in c._labourerslist) { // get the project allocation id where the labourer id is entered c._project_labour_working_day = new project_labour_working_day(); c._project_labour_working_day.project_labour_allocation_id = DB1.GetProjectLabourAllocation("SELECT a.* FROM project_labour_allocation a , labourers b WHERE a.labourer_id = b.labourer_id AND b.labourer_id = " + labour.labourer_id + "").First().project_labour_allocation_id; c._project_labour_working_day.working_date = DateTime.Now.Date; if(!DB1.InsertValue(c , Constants.Project_Labour_Working_Day)) { MessageBox.Show("labourer not entered"); } } foreach (employees emp in c._employeeslist) { c._project_employee_working_day = new project_employee_working_day(); c._project_employee_working_day.project_employee_allocation_id = DB1.GetProjectEmployeeAllocation("SELECT a.* FROM project_employee_allocation a , employees b WHERE a.employee_id = b.employee_id AND b.employee_id = " + emp.employee_id + "").First().project_employee_allocation_id; c._project_employee_working_day.working_date = DateTime.Now.Date; if (!DB1.InsertValue(c, Constants.Project_employee_Working_Day)) { MessageBox.Show("employee not entered"); } } MessageBox.Show("data entered"); break; } return req; } catch { return null ; } }