public ActivitiesListResponse GetActivitiesList(ActivityFilters filters) { ActivitiesListResponse response = new ActivitiesListResponse(); try { List <Activity> activitiesList = _context.Activities.ToList(); if (filters.company != 0 || filters.fromDate != "" || filters.toDate != "") { if (filters.company != 0) { activitiesList = activitiesList.Where((x) => x.Company == filters.company).ToList(); } if (filters.fromDate != "") { activitiesList = activitiesList.Where((x) => x.InsertDate >= Convert.ToDateTime(filters.fromDate)).ToList(); } if (filters.toDate != "") { activitiesList = activitiesList.Where((x) => x.InsertDate <= Convert.ToDateTime(filters.toDate)).ToList(); } } foreach (Activity item in activitiesList) { ENTITIES.Activity newActivity = new ENTITIES.Activity(); Copy(ref newActivity, item); List <ENTITIES.JBI> activitiesJBI = new List <ENTITIES.JBI>(); List <ActivityJBI> JBIlist = _context.ActivityJBIs.Where(x => x.ActivityId == item.ActivityId).ToList(); foreach (ActivityJBI jbi in JBIlist) { JBI onePerson = _context.JBIs.Where(x => x.Moneln == jbi.JBIId).FirstOrDefault(); ENTITIES.JBI oneJBI = new ENTITIES.JBI(); Copy(ref oneJBI, onePerson); activitiesJBI.Add(oneJBI); } List <ENTITIES.TextBox> activitiesTextBoxes = new List <ENTITIES.TextBox>(); List <TextBox> textBoxes = _context.TextBoxes.Where(x => x.ActivityId == item.ActivityId).ToList(); foreach (TextBox textBox in textBoxes) { ENTITIES.TextBox oneTextBox = new ENTITIES.TextBox(); Copy(ref oneTextBox, textBox); oneTextBox.BoxId = textBox.TextBoxId; activitiesTextBoxes.Add(oneTextBox); } newActivity.JBIlist = activitiesJBI.ToArray(); newActivity.TextBoxList = activitiesTextBoxes.ToArray(); response.Activities.Add(newActivity); } } catch (Exception ex) { response.desc = ex.Message; response.rc = -1; } return(response); }
public ActivitiesListResponse GetActivitiesList(ActivityFilters filters) { ActivitiesListResponse response = new ActivitiesListResponse(); using (DalActivity context = new DalActivity()) { response = context.GetActivitiesList(filters); } return(response); }
// GET: api/Activity public ActivitiesListResponse GetActivitiesList(int company = 0, string fromDate = "", string toDate = "") { ActivityFilters filters = new ActivityFilters(); if (company != 0) { filters.company = company; } if (fromDate != "") { filters.fromDate = fromDate; } if (toDate != "") { filters.toDate = toDate; } ActivitiesListResponse response = new ActivitiesListResponse(); try { using (var manager = new ActivityManager()) { response = manager.GetActivitiesList(filters); } } catch (Exception ex) { //-----------------------------------------------------------------------------adderror to db--------------------------------------------------------------------------------------------- response.title = "Error in GetActivitiesList function"; response.body = ex.Message; response.rc = 99; } return(response); }