public static Guid GetCurCompanyId(DataModelContainer db) { Guid curUserId = AccountHelper.GetCurUserId(); PartnerAdmin pa = db.PartnerAdmins.Find(curUserId); if (pa != null) return pa.PartnerCompanyId; PartnerStaffMember psm = db.PartnerStaffMembers.Find(curUserId); if (psm != null) return psm.PartnerCompanyId; throw new Exception("Can't get company Id"); }
static bool RecordHistory(Object obj, bool create) { try { DataModelContainer db = new DataModelContainer(); HistoryRec hr = new HistoryRec(); hr.TimeStamp = DateTime.UtcNow; hr.User = AccountHelper.GetCurUserId(); hr.Created = create; Dictionary<string, object> dict = null; if (obj is Beneficiary) { Beneficiary bf = (Beneficiary)obj; hr.Type = (byte)Constants.HistoryType.BENEFICIARY; hr.RefId = bf.Id; dict = getValue(bf); } else if (obj is PartnerStaffMember) { PartnerStaffMember sm = (PartnerStaffMember)obj; hr.Type = (byte)Constants.HistoryType.STAFF_MEMBER; hr.RefId = sm.Id; dict = getValue(sm); } else if (obj is PartnerAdmin) { PartnerAdmin pa = (PartnerAdmin)obj; hr.Type = (byte)Constants.HistoryType.PARTNER_ADMIN; hr.RefId = pa.Id; dict = getValue(pa); } else if (obj is Adult) { Adult ad = (Adult)obj; hr.Type = (byte)Constants.HistoryType.ADULT; hr.RefId = ad.Id; dict = getValue(ad); } else if (obj is Child) { Child ch = (Child)obj; hr.Type = (byte)Constants.HistoryType.CHILD; hr.RefId = ch.Id; dict = getValue(ch); } else if (obj is HousingInfo) { HousingInfo hi = (HousingInfo)obj; hr.Type = (byte)Constants.HistoryType.HOUSEHOLD_INFO; hr.RefId = hi.Id; dict = getValue(hi); } else if (obj is GovernmentServicesInfo) { GovernmentServicesInfo si = (GovernmentServicesInfo)obj; hr.Type = (byte)Constants.HistoryType.GOVERNMENT_SERVICES; hr.RefId = si.Id; dict = getValue(si); } else if (obj is MajorExpensesInfo) { MajorExpensesInfo me = (MajorExpensesInfo)obj; hr.Type = (byte)Constants.HistoryType.MAJOR_EXPENSES; hr.RefId = me.Id; dict = getValue(me); } else if (obj is HealthCareInfo) { HealthCareInfo hci = (HealthCareInfo)obj; hr.Type = (byte)Constants.HistoryType.HEALTHCARE; hr.RefId = hci.Id; dict = getValue(hci); } else if (obj is HouseholdAsset) { HouseholdAsset ha = (HouseholdAsset)obj; hr.Type = (byte)Constants.HistoryType.HOUSEHOLD_ASSET; hr.RefId = new Guid(FormatHelper.FormatAsGuid(ha.Id)); dict = getValue(ha); } else if (obj is Town) { Town t = (Town)obj; hr.Type = (byte)Constants.HistoryType.TOWN; hr.RefId = new Guid(FormatHelper.FormatAsGuid(t.Id)); dict = getValue(t); } else if (obj is Meals) { Meals m = (Meals)obj; hr.Type = (byte)Constants.HistoryType.MEALS; hr.RefId = m.Id; dict = getValue(m); } else { // Unsupported type return false; } hr.Value = (new JavaScriptSerializer()).Serialize(dict); db.HistoryRecs.Add(hr); db.SaveChanges(); } catch(Exception ex) { return false; } return true; }