public JBISpecificResponse GetSpecificJBI(int idJBI) { JBISpecificResponse response = new JBISpecificResponse(); try { JBI one = _context.JBIs.Where((x) => x.Moneln == idJBI).FirstOrDefault(); if (one != null) { response.JBI = ConvertJBI(one); response.rc = 0; response.title = "Get one JBI success"; } else { response.rc = 1; response.title = "Id is not found"; } } catch (Exception ex) { var message = ex.Message; response.desc = ex.Message; } return(response); }
public CrmResponse AddNewJbi(ENTITIES.JBI jbi) { CrmResponse response = new CrmResponse(); try { JBI newJbi = new JBI(); Type myType = newJbi.GetType(); PropertyInfo[] props = myType.GetProperties(); foreach (PropertyInfo prop in props) { object jbiValue = jbi.GetType().GetProperty(prop.Name).GetValue(jbi); newJbi.GetType().GetProperty(prop.Name).SetValue(newJbi, jbiValue); } _context.JBIs.Add(newJbi); _context.SaveChanges(); jbi.Moneln = _context.JBIs.Max().Moneln; } catch (Exception ex) { var message = ex.Message; response.desc = ex.Message; } return(response); }
public CrmResponse DeleteJBI(int idJBI) { CrmResponse response = new CrmResponse(); try { JBI one = _context.JBIs.Where((x) => x.Moneln == idJBI).FirstOrDefault(); if (one != null) { _context.JBIs.Remove(one); _context.SaveChanges(); response.rc = 0; response.title = "Delete one JBI success"; } else { response.rc = 1; response.title = "Id is not found"; } } catch (Exception ex) { var message = ex.Message; response.desc = ex.Message; } return(response); }
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); }
private ENTITIES.JBI ConvertJBI(JBI item) { ENTITIES.JBI response = new ENTITIES.JBI(); response.Moneln = item.Moneln; response.FirstName = item.FirstName; response.LastName = item.LastName; response.Phone = item.Phone; response.Facebook = item.Facebook; response.Linkedin = item.Linkedin; response.Email = item.Email; return(response); }
public CrmResponse UpdateJBI(ENTITIES.JBI jbi) { CrmResponse response = new CrmResponse(); try { JBI updatedRow = _context.JBIs.Where((x) => x.Moneln == jbi.Moneln).FirstOrDefault(); if (updatedRow != null) { Type myType = updatedRow.GetType(); PropertyInfo[] props = myType.GetProperties(); foreach (PropertyInfo prop in props) { //object oneKey = prop.Name; //object onevalue = prop.GetValue(updatedRow, new object[] { }); object jbiValue = jbi.GetType().GetProperty(prop.Name).GetValue(jbi); updatedRow.GetType().GetProperty(prop.Name).SetValue(updatedRow, jbiValue); } _context.SaveChanges(); } else { response.rc = 1; response.title = "Id is not found"; } } catch (Exception ex) { var message = ex.Message; response.desc = ex.Message; } return(response); }