public bool ImportAllActiveChildFamily(Guid SchoolYearId, Guid SchoolId, Guid OldCurrentSchoolYearId, System.Data.Common.DbTransaction tran, DayCareDataContext dbold) { DayCarePL.Logger.Write(DayCarePL.LogType.INFO, DayCarePL.ModuleToLog.clChildFamily, "ImportAllActiveChildFamily", "Execute ImportAllActiveChildFamily Method", DayCarePL.Common.GUID_DEFAULT); clConnection.DoConnection(); DayCareDataContext db = dbold; db.Transaction = tran; ChildFamilySchoolYear DBChildFamilySchoolYear = null; try { this.ImportActiveChildFamilyCount = 0; DayCarePL.Logger.Write(DayCarePL.LogType.DEBUG, DayCarePL.ModuleToLog.clChildFamily, "ImportAllActiveChildFamily", "Debug ImportAllActiveChildFamily Method", DayCarePL.Common.GUID_DEFAULT); //Guid currentschoolyearid = (from sy in db.SchoolYears // where sy.CurrentId.Equals(true) // select sy.Id).SingleOrDefault(); //List<Guid> lstChildFamily = (from c in db.ChildDatas // join cf in db.ChildFamilies on c.ChildFamilyId equals cf.Id // where cf.SchoolId.Equals(SchoolId) && c.Active.Equals(true) // && !(from cy in db.ChildSchoolYears // where cy.SchoolYearId.Equals(SchoolYearId) // select cy.ChildDataId).Contains(c.Id) // select c.Id).ToList(); List <Guid> lstChildFamily = (from cf in db.ChildFamilies join cfsy in db.ChildFamilySchoolYears on cf.Id equals cfsy.ChildFamilyId where cf.SchoolId.Equals(SchoolId) && cfsy.active.Equals(true) && cfsy.SchoolYearId.Equals(OldCurrentSchoolYearId) && !(from cy in db.ChildFamilySchoolYears where cy.SchoolYearId.Equals(SchoolYearId) select cy.ChildFamilyId).Contains(cf.Id) select cf.Id).ToList(); //var Data = db.spGetChildIdNotInChildSchoolYear(SchoolId, SchoolYearId); foreach (Guid ChildFamilyId in lstChildFamily) { try { this.ImportActiveChildFamilyCount = lstChildFamily.Count; DBChildFamilySchoolYear = new ChildFamilySchoolYear(); DBChildFamilySchoolYear.Id = Guid.NewGuid(); DBChildFamilySchoolYear.ChildFamilyId = ChildFamilyId; DBChildFamilySchoolYear.SchoolYearId = SchoolYearId; DBChildFamilySchoolYear.active = true; db.ChildFamilySchoolYears.InsertOnSubmit(DBChildFamilySchoolYear); db.SubmitChanges(); } catch { } } return(true); } catch (Exception ex) { DayCarePL.Logger.Write(DayCarePL.LogType.EXCEPTION, DayCarePL.ModuleToLog.clChildFamily, "ImportAllActiveChildFamily", ex.Message.ToString(), DayCarePL.Common.GUID_DEFAULT); return(false); } }
//Import All Selected Child of school, Dt: 11-April-2013, DB: A public static bool ImportAllSelectedChild(Guid ChildDataId, Guid ChildFamilyId, Guid SchoolYearId) { DayCarePL.Logger.Write(DayCarePL.LogType.INFO, DayCarePL.ModuleToLog.clChildSchoolYear, "ImportAllSelectedChild", "Execute ImportAllSelectedChild Method", DayCarePL.Common.GUID_DEFAULT); clConnection.DoConnection(); DayCareDataContext db = new DayCareDataContext(); System.Data.Common.DbTransaction tran = null; try { DayCarePL.Logger.Write(DayCarePL.LogType.DEBUG, DayCarePL.ModuleToLog.clChildSchoolYear, "ImportAllSelectedChild", "Debug ImportAllSelectedChild Method", DayCarePL.Common.GUID_DEFAULT); //ChildSchoolYear if (db.Connection.State == System.Data.ConnectionState.Closed) { db.Connection.Open(); } tran = db.Connection.BeginTransaction(); db.Transaction = tran; //ChildFamilySchoolYear bool IsActive = true; ChildFamilySchoolYear DBChildFamilySchoolYear = db.ChildFamilySchoolYears.FirstOrDefault(i => i.ChildFamilyId.Equals(ChildFamilyId) && i.SchoolYearId.Equals(SchoolYearId)); if (DBChildFamilySchoolYear == null) { DBChildFamilySchoolYear = new ChildFamilySchoolYear(); DBChildFamilySchoolYear.Id = Guid.NewGuid(); DBChildFamilySchoolYear.ChildFamilyId = ChildFamilyId; DBChildFamilySchoolYear.SchoolYearId = SchoolYearId; DBChildFamilySchoolYear.active = true; db.ChildFamilySchoolYears.InsertOnSubmit(DBChildFamilySchoolYear); db.SubmitChanges(); } else { IsActive = DBChildFamilySchoolYear.active == null ? false : DBChildFamilySchoolYear.active.Value; } ChildSchoolYear DBChildSchoolYear = db.ChildSchoolYears.FirstOrDefault(i => i.ChildDataId.Equals(ChildDataId) && i.SchoolYearId.Equals(SchoolYearId)); if (DBChildSchoolYear == null) { DBChildSchoolYear = new ChildSchoolYear(); DBChildSchoolYear.Id = Guid.NewGuid(); DBChildSchoolYear.ChildDataId = ChildDataId; DBChildSchoolYear.SchoolYearId = SchoolYearId; DBChildSchoolYear.active = IsActive; db.ChildSchoolYears.InsertOnSubmit(DBChildSchoolYear); db.SubmitChanges(); } tran.Commit(); return(true); } catch (Exception ex) { DayCarePL.Logger.Write(DayCarePL.LogType.EXCEPTION, DayCarePL.ModuleToLog.clChildSchoolYear, "ImportAllSelectedChild", ex.Message.ToString(), DayCarePL.Common.GUID_DEFAULT); if (tran != null) { tran.Rollback(); } return(false); } finally { if (db.Connection.State == System.Data.ConnectionState.Open) { db.Connection.Close(); } } }