Esempio n. 1
0
        public static bool ImportAllActiveClassRoom(Guid SchoolYearId, Guid SchoolId, Guid OldCurrentSchoolYearId, System.Data.Common.DbTransaction tran, DayCareDataContext dbold)
        {
            DayCarePL.Logger.Write(DayCarePL.LogType.INFO, DayCarePL.ModuleToLog.ClassRoom, "ImportAllActiveClassRoom", "Execute ImportAllActiveClassRoom Method", DayCarePL.Common.GUID_DEFAULT);
            clConnection.DoConnection();

            DayCareDataContext db = dbold;

            db.Transaction = tran;
            ClassRoomSchoolYear DBClassRoomSchoolYear = null;

            try
            {
                DayCarePL.Logger.Write(DayCarePL.LogType.DEBUG, DayCarePL.ModuleToLog.ClassRoom, "ImportAllActiveClassRoom", "Debug ImportAllActiveClassRoom Method", DayCarePL.Common.GUID_DEFAULT);
                Guid currentschoolyearid = SchoolYearId;
                List <DayCarePL.ClassRoomProperties> lstClassroom = (from cr in db.ClassRooms
                                                                     join sy in db.SchoolYears on cr.SchoolId equals sy.SchoolId
                                                                     where cr.SchoolId.Equals(SchoolId) &&
                                                                     sy.Id.Equals(OldCurrentSchoolYearId) &&
                                                                     !(from crsy in db.ClassRoomSchoolYears
                                                                       where crsy.SchoolYearId.Equals(currentschoolyearid)
                                                                       select crsy.ClassRoomId).Contains(cr.Id)
                                                                     select new DayCarePL.ClassRoomProperties()
                {
                    Id = cr.Id,
                    SchoolYearId = sy.Id,
                    Active = cr.Active,
                    StaffId = cr.StaffId,
                    LastModifiedById = cr.LastModifiedById,
                    Name = cr.Name
                }).ToList();

                foreach (DayCarePL.ClassRoomProperties objClassroom in lstClassroom)
                {
                    DBClassRoomSchoolYear                      = new ClassRoomSchoolYear();
                    DBClassRoomSchoolYear.Id                   = Guid.NewGuid();
                    DBClassRoomSchoolYear.ClassRoomId          = objClassroom.Id;
                    DBClassRoomSchoolYear.SchoolYearId         = SchoolYearId;
                    DBClassRoomSchoolYear.Active               = objClassroom.Active;
                    DBClassRoomSchoolYear.StaffId              = objClassroom.StaffId;
                    DBClassRoomSchoolYear.CreatedById          = objClassroom.LastModifiedById;
                    DBClassRoomSchoolYear.CreatedDateTime      = DateTime.Now.Date;
                    DBClassRoomSchoolYear.LastModifiedById     = objClassroom.LastModifiedById;
                    DBClassRoomSchoolYear.LastModifiedDateTime = DateTime.Now.Date;
                    DBClassRoomSchoolYear.ClassRoomName        = objClassroom.Name;
                    db.ClassRoomSchoolYears.InsertOnSubmit(DBClassRoomSchoolYear);
                    db.SubmitChanges();
                }
            }
            catch
            {
            }
            return(true);
        }
Esempio n. 2
0
        public static bool Delete(Guid Id, Guid SchoolYearID)
        {
            bool result = false;

            DayCarePL.Logger.Write(DayCarePL.LogType.INFO, DayCarePL.ModuleToLog.clClassRoom, "Delete", "Delete Method", DayCarePL.Common.GUID_DEFAULT);
            clConnection.DoConnection();
            DayCareDataContext db = new DayCareDataContext();

            try
            {
                DayCarePL.Logger.Write(DayCarePL.LogType.DEBUG, DayCarePL.ModuleToLog.clClassRoom, "Delete", "Debug Delete Method", DayCarePL.Common.GUID_DEFAULT);

                ClassRoom DBClassRoom = db.ClassRooms.FirstOrDefault(c => c.Id.Equals(Id));

                ProgClassRoom DBProgClassRoom = db.ProgClassRooms.FirstOrDefault(pc => pc.ClassRoomId.Equals(Id) && pc.ClassRoomSchoolYearId.Equals(SchoolYearID));

                ClassRoomSchoolYear DBClassRoomSchoolYear = db.ClassRoomSchoolYears.FirstOrDefault(crsy => crsy.ClassRoomId.Equals(Id) && crsy.SchoolYearId.Equals(SchoolYearID));

                if (DBClassRoomSchoolYear != null)
                {
                    db.ClassRoomSchoolYears.DeleteOnSubmit(DBClassRoomSchoolYear);
                }
                if (DBProgClassRoom != null)
                {
                    db.ProgClassRooms.DeleteOnSubmit(DBProgClassRoom);
                    db.SubmitChanges();
                    result = true;
                }
                if (DBClassRoom != null)
                {
                    db.ClassRooms.DeleteOnSubmit(DBClassRoom);
                    db.SubmitChanges();
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            catch (Exception ex)
            {
                DayCarePL.Logger.Write(DayCarePL.LogType.EXCEPTION, DayCarePL.ModuleToLog.clClassRoom, "Delete", ex.Message.ToString(), DayCarePL.Common.GUID_DEFAULT);
                result = false;
            }
            return(result);
        }
Esempio n. 3
0
        public static bool SaveClassRoomYearWise(DayCarePL.ClassRoomProperties objClassRoom, Guid SchoolYearId)
        {
            DayCarePL.Logger.Write(DayCarePL.LogType.INFO, DayCarePL.ModuleToLog.clClassRoom, "Save", "Execute Save Method", DayCarePL.Common.GUID_DEFAULT);
            clConnection.DoConnection();
            bool result = false;

            //declare trans variable
            System.Data.Common.DbTransaction trans = null;

            DayCareDataContext  db                    = new DayCareDataContext();
            ClassRoom           DBClassRoom           = null;
            ClassRoomSchoolYear DBClassRoomSchoolYear = null;

            try
            {
                // Open the connection
                db.Connection.Open();

                // Begin the transaction
                trans = db.Connection.BeginTransaction();
                // Assign transaction to context class
                // All the database operation perform by this object will now use
                //transaction
                db.Transaction = trans;

                DayCarePL.Logger.Write(DayCarePL.LogType.DEBUG, DayCarePL.ModuleToLog.clClassRoom, "Save", "Debug Save Method", DayCarePL.Common.GUID_DEFAULT);
                if (objClassRoom.Id.ToString().Equals(DayCarePL.Common.GUID_DEFAULT))
                {
                    DBClassRoom    = new ClassRoom();
                    DBClassRoom.Id = System.Guid.NewGuid();

                    DBClassRoomSchoolYear                 = new ClassRoomSchoolYear();
                    DBClassRoomSchoolYear.Id              = System.Guid.NewGuid();
                    DBClassRoomSchoolYear.ClassRoomName   = objClassRoom.Name;
                    DBClassRoomSchoolYear.CreatedById     = objClassRoom.LastModifiedById;
                    DBClassRoomSchoolYear.CreatedDateTime = DateTime.Now;
                }
                else
                {
                    DBClassRoom           = db.ClassRooms.SingleOrDefault(D => D.Id.Equals(objClassRoom.Id));
                    DBClassRoomSchoolYear = db.ClassRoomSchoolYears.FirstOrDefault(u => u.ClassRoomId.Equals(objClassRoom.Id) && u.SchoolYearId.Equals(SchoolYearId));
                }
                DBClassRoom.LastModifiedById     = objClassRoom.LastModifiedById;
                DBClassRoom.LastModifiedDatetime = DateTime.Now;
                DBClassRoom.Name     = objClassRoom.Name;
                DBClassRoom.SchoolId = objClassRoom.SchoolId;
                DBClassRoom.MaxSize  = objClassRoom.MaxSize;
                DBClassRoom.Active   = objClassRoom.Active;
                DBClassRoom.StaffId  = objClassRoom.StaffId;

                //class school year
                DBClassRoomSchoolYear.ClassRoomId          = DBClassRoom.Id;
                DBClassRoomSchoolYear.SchoolYearId         = SchoolYearId;
                DBClassRoomSchoolYear.Active               = objClassRoom.Active;
                DBClassRoomSchoolYear.StaffId              = objClassRoom.StaffId;
                DBClassRoomSchoolYear.ClassRoomName        = objClassRoom.Name;
                DBClassRoomSchoolYear.LastModifiedById     = objClassRoom.LastModifiedById;
                DBClassRoomSchoolYear.LastModifiedDateTime = DateTime.Now;


                if (objClassRoom.Id.ToString().Equals(DayCarePL.Common.GUID_DEFAULT))
                {
                    db.ClassRooms.InsertOnSubmit(DBClassRoom);
                    db.ClassRoomSchoolYears.InsertOnSubmit(DBClassRoomSchoolYear);
                }

                db.SubmitChanges();

                // Commit transaction
                trans.Commit();

                result = true;
            }
            catch (Exception ex)
            {
                DayCarePL.Logger.Write(DayCarePL.LogType.EXCEPTION, DayCarePL.ModuleToLog.clClassRoom, "Save", ex.Message.ToString(), DayCarePL.Common.GUID_DEFAULT);
                result = false;

                // Rollback transaction
                if (trans != null)
                {
                    trans.Rollback();
                }
            }
            finally
            {
                // Close the connection
                if (db.Connection.State == ConnectionState.Open)
                {
                    db.Connection.Close();
                }
            }
            return(result);
        }