예제 #1
0
        public void Seed()
        {
            // SchoolType seeder
            var schoolTypes = new DbEntities.Office.SchoolType[]
            {
                new DbEntities.Office.SchoolType {
                    Name = "Graduate"
                },
                new DbEntities.Office.SchoolType {
                    Name = "Undergraduate"
                },
                new DbEntities.Office.SchoolType {
                    Name = "Higher Secondary"
                },
                new DbEntities.Office.SchoolType {
                    Name = "Secondary"
                },
            };

            _context.SchoolType.AddOrUpdate(
                p => p.Name,
                schoolTypes
                );
            _context.SaveChanges();

            // School Seeder
            var underGradSchoolType = _context.SchoolType.FirstOrDefault(x => x.Name == "Undergraduate");
            var schools             = new DbEntities.Office.School[]
            {
                new DbEntities.Office.School {
                    Name            = "Nepal Engineering College",
                    Code            = SchoolSeeder.NEC_CODE,
                    Address         = "Changunarayan, Bhaktapur, Nepal",
                    IsActive        = true,
                    IsDeleted       = false,
                    PhoneAfterHours = "",
                    PhoneMain       = "",
                    SchoolTypeId    = underGradSchoolType.Id,
                    UserId          = null,
                    Website         = "http://nec.edu.np",
                    CreatedDate     = DateTime.Now,
                    Description     = "",
                    EmailGeneral    = "",
                    EmailMarketing  = "",
                    EmailSupport    = "",
                    ImageId         = 0
                }
            };

            _context.School.AddOrUpdate(
                p => p.Name,
                schools
                );
            _context.SaveChanges();
        }
예제 #2
0
            //used



            #endregion


            //----------------------Add or update- --------------------------//
            #region Add or Update functions

            public Academic.DbEntities.Batches.Batch AddOrUpdateBatch(DbEntities.Batches.Batch batch
                                                                      , List <ProgramBatch> progBatchList)
            {
                try
                {
                    using (var scope = new TransactionScope())
                    {
                        var ent = Context.Batch.Find(batch.Id);
                        if (ent == null)
                        {
                            ent = Context.Batch.Add(batch);
                            Context.SaveChanges();
                            foreach (var pb in progBatchList)
                            {
                                pb.BatchId = ent.Id;
                                Context.ProgramBatch.Add(pb);
                                Context.SaveChanges();
                            }
                        }
                        else
                        {
                            ent.Name        = batch.Name;
                            ent.Description = batch.Description;

                            //ent.ClassCommenceDate = batch.ClassCommenceDate;
                            //ent.Void = batch.Void

                            Context.SaveChanges();
                            foreach (var pb in progBatchList)
                            {
                                var found = Context.ProgramBatch.Find(pb.Id);
                                if (found == null)
                                {
                                    Context.ProgramBatch.Add(pb);
                                    Context.SaveChanges();
                                }
                                else
                                {
                                    found.Void = pb.Void;
                                    Context.SaveChanges();
                                }
                            }
                        }
                        scope.Complete();
                        return(ent);
                    }
                }
                catch
                {
                    return(null);
                }
            }
예제 #3
0
            public UserInfoModel CreateUserAndAccount(string username, string password)
            {
                //encrypt password and check with db
                Users user = Context.Users.FirstOrDefault(x => x.UserName.ToLower() == username.ToLower() && x.Password == password);

                if (user != null)
                {
                    return(null);
                }
                var newUser = new Users()
                {
                    UserName = username, Password = password, RoleId = 2
                };

                Context.Users.Add(newUser);
                Context.Entry <Users>(newUser).State = System.Data.EntityState.Added;
                Context.SaveChanges();
                var model = new UserInfoModel()
                {
                    Username = user.UserName,
                    FullName = user.FullName
                };

                return(model);
            }
예제 #4
0
            public string Register(DbEntities.User.Users user)
            {
                try
                {
                    var xUser = Context.Users.FirstOrDefault(x => x.UserName == user.UserName);
                    if (xUser == null)
                    {
                        using (var scope = new TransactionScope())
                        {
                            var savedUser = Context.Users.Add(user);
                            Context.SaveChanges();
                            var roleId = Context.Role.FirstOrDefault(x => x.RoleName == "manager");
                            if (roleId == null)
                            {
                                roleId = Context.Role.Add(new Role()
                                {
                                    DisplayName = "Manager"
                                    ,
                                    RoleName = "manager"
                                    ,
                                    Description = "'Manager' has complete access over all of the settings."
                                });
                                Context.SaveChanges();
                            }
                            var urole = new UserRole()
                            {
                                AssignedDate = DateTime.Now
                                ,
                                UserId = savedUser.Id
                                ,
                                RoleId = roleId.Id
                            };

                            Context.UserRole.Add(urole);
                            Context.SaveChanges();
                            scope.Complete();
                            return("success");
                        }
                    }
                    return("Username already exist.");
                }
                catch (Exception e)
                {
                    return("Error while creating user.");
                }
            }
예제 #5
0
            public DbEntities.Events.Event AddOrUpdateEvent(DbEntities.Events.Event evnt)
            {
                var found = Context.Event.Find(evnt.Id);

                if (found == null)
                {
                    found = Context.Event.Add(evnt);
                    Context.SaveChanges();
                }
                else
                {
                    found.Date        = evnt.Date;
                    found.Description = evnt.Description;
                    found.Location    = evnt.Location;
                    found.Title       = evnt.Title;
                    found.Time        = evnt.Time;
                    found.Latitude    = evnt.Latitude;
                    found.Longitude   = evnt.Longitude;
                    Context.SaveChanges();
                }
                return(found);
            }
예제 #6
0
        public Review Post(int id, [FromBody] Review r)
        {
            var professor = _db.Professors.Where(p => p.ProfessorID == id);

            if (professor != null)
            {
                r.Posted      = DateTime.Now;
                r.ProfessorID = id;
                _db.Reviews.Add(r);
                _db.SaveChanges();
            }
            return(r);
        }
예제 #7
0
            public DbEntities.Teachers.Teacher Add(TeacherVM modelVm)
            {
                TeacherViewModel model = modelVm.Teacher;
                var quali = modelVm.TeacherQualification;

                using (var ctx = new DbHelper.WorkingWithFiles())
                {
                    //var imId = ctx.UploadImageToDB(model.Image);
                    var convert = Convert(model);
                    //convert.ImageFileId = imId;
                    var teach = Context.Teacher.Add(convert);

                    Context.SaveChanges();

                    for (var i = 0; i < quali.Count; i++)
                    {
                        quali[i].TeacherId = teach.Id;
                        Context.TeacherQualification.Add(quali[i]);
                    }
                    Context.SaveChanges();
                    return(teach);
                }
            }
예제 #8
0
        public void Seed()
        {
            // Grade seed
            var grades = new DbEntities.Grades.Grade[]
            {
                new DbEntities.Grades.Grade {
                    Name = "Range", Description = "", GradeValueIsInPercentOrPostition = false, TotalMaxValue = 100, TotalMinValue = 0, MinimumPassValue = 40, SchoolId = null, RangeOrValue = false, Void = null,
                },
                new DbEntities.Grades.Grade {
                    Name        = "Letter Grading", Description = "", GradeValueIsInPercentOrPostition = false, TotalMaxValue = 100, TotalMinValue = 0, MinimumPassValue = 40, SchoolId = null, RangeOrValue = true, Void = null,
                    GradeValues = new List <DbEntities.Grades.GradeValue> {
                        new DbEntities.Grades.GradeValue {
                            Value = "F", IsFailGrade = false, EquivalentPercentOrPostition = 0, Void = null,
                        },
                        new DbEntities.Grades.GradeValue {
                            Value = "C-", IsFailGrade = false, EquivalentPercentOrPostition = 1.7f, Void = null,
                        },
                        new DbEntities.Grades.GradeValue {
                            Value = "C", IsFailGrade = false, EquivalentPercentOrPostition = 2f, Void = null,
                        },
                        new DbEntities.Grades.GradeValue {
                            Value = "C+", IsFailGrade = false, EquivalentPercentOrPostition = 2.3f, Void = null,
                        },
                        new DbEntities.Grades.GradeValue {
                            Value = "B-", IsFailGrade = false, EquivalentPercentOrPostition = 2.7f, Void = null,
                        },
                        new DbEntities.Grades.GradeValue {
                            Value = "B", IsFailGrade = false, EquivalentPercentOrPostition = 3, Void = null,
                        },
                        new DbEntities.Grades.GradeValue {
                            Value = "B+", IsFailGrade = false, EquivalentPercentOrPostition = 3.3f, Void = null,
                        },
                        new DbEntities.Grades.GradeValue {
                            Value = "A-", IsFailGrade = false, EquivalentPercentOrPostition = 3.7f, Void = null,
                        },
                        new DbEntities.Grades.GradeValue {
                            Value = "A", IsFailGrade = false, EquivalentPercentOrPostition = 4, Void = null,
                        },
                        //new DbEntities.Grades.GradeValue{Value = "A+", IsFailGrade = false, EquivalentPercentOrPostition = 0, Void = null, },
                    }
                },
            };

            _context.Grade.AddOrUpdate(
                p => p.Name,
                grades
                );
            _context.SaveChanges();
        }
예제 #9
0
        public void Seed()
        {
            var userFiles = new DbEntities.UserFile[]
            {
                new DbEntities.UserFile {
                    DisplayName = "User Photos", FileType = "Folder", IsServerFile = true, IsFolder = true, IsConstantAndNotEditable = true, CreatedDate = DateTime.Now, FileName = null, FileDirectory = null, FileSizeInBytes = 0, ModifiedBy = null, ModifiedDate = null, CreatedBy = null, FolderId = null, IconPath = null, SchoolId = null, Void = null,
                },
            };

            _context.File.AddOrUpdate(
                p => p.DisplayName,
                userFiles
                );
            _context.SaveChanges();
        }
예제 #10
0
 public DbEntities.Subjects.SubjectSection AddOrUpdateSection(DbEntities.Subjects.SubjectSection sec
                                                              , DbEntities.AccessPermission.Restriction restriction)
 {
     try
     {
         using (var actresHelper = new DbHelper.ActAndRes())
             using (var scope = new TransactionScope())
             {
                 var ent = Context.SubjectSection.Find(sec.Id);
                 if (ent == null)
                 {
                     var res = actresHelper.AddOrUpdateRestriction(0, restriction);
                     sec.RestrictionId = res.Id;
                     ent = Context.SubjectSection.Add(sec);
                 }
                 else
                 {
                     ent.Name        = sec.Name;
                     ent.Summary     = sec.Summary;
                     ent.ShowSummary = sec.ShowSummary;
                     var res = actresHelper.AddOrUpdateRestriction(0, restriction);
                     if ((ent.RestrictionId ?? 0) == 0)
                     {
                         ent.RestrictionId = res.Id;
                     }
                 }
                 Context.SaveChanges();
                 scope.Complete();
                 return(ent);
             }
     }
     catch (Exception)
     {
         return(null);
     }
 }
예제 #11
0
        public void Seed()
        {
            var school = _context.School.First(x => x.Code == SchoolSeeder.NEC_CODE);
            var computerProgram = _context.Program.First(x => x.Name == ProgramSeeder.COMPUTER_PROGRAM_NAME);

            var academicYears = new DbEntities.AcademicYear[]
            {
                new DbEntities.AcademicYear
                {
                    StartDate = new DateTime(DateTime.Now.Year, 1, 1),
                    EndDate = new DateTime(DateTime.Now.Year, 12, 31),
                    IsActive = true,
                    Name = DateTime.Now.Year.ToString(),
                    SchoolId = school.Id,
                    Sessions = new List<DbEntities.Session>
                    {
                        new DbEntities.Session{Name = "Fall", StartDate = new DateTime(DateTime.Now.Year, 1,1), Position = 1, EndDate = new DateTime(DateTime.Now.Year, 6, 15)},
                        new DbEntities.Session{Name = "Spring", StartDate = new DateTime(DateTime.Now.Year, 6,16), Position = 1, EndDate = new DateTime(DateTime.Now.Year, 12, 31)},
                    },
                    Batches = new List<Academic.DbEntities.Batches.Batch>
                    {
                        new DbEntities.Batches.Batch
                        {
                            Name = DateTime.Now.Year.ToString().Substring(1),
                            CreatedDate = DateTime.Now,
                            Description = "",
                            SchoolId = school.Id,
                            ProgramBatches = new List<DbEntities.Batches.ProgramBatch>
                            {
                                new DbEntities.Batches.ProgramBatch{ProgramId = computerProgram.Id, }
                            }
                        },
                    },
                    Position = 1,
                }
            };
            _context.AcademicYear.AddOrUpdate(
                p => p.Name,
                academicYears
                );
            _context.SaveChanges();

        }
예제 #12
0
파일: RoleSeeder.cs 프로젝트: skrishnau/LMS
        public void Seed()
        {
            var roles = new DbEntities.User.Role[]
            {
                new DbEntities.User.Role {
                    RoleName = ADMIN_ROLE_NAME, DisplayName = "Admin", Description = "", SchoolId = null, Void = null
                },
                new DbEntities.User.Role {
                    RoleName = MANAGER_ROLE_NAME, DisplayName = "Manager", Description = "", SchoolId = null, Void = null
                },
                new DbEntities.User.Role {
                    RoleName = TEACHER_ROLE_NAME, DisplayName = "Teacher", Description = "", SchoolId = null, Void = null
                },
                new DbEntities.User.Role {
                    RoleName = STUDENT_ROLE_NAME, DisplayName = "Student", Description = "", SchoolId = null, Void = null
                },
                new DbEntities.User.Role {
                    RoleName = COURSE_EDITOR_ROLE_NAME, DisplayName = "Course Editor", Description = "", SchoolId = null, Void = null
                },
                new DbEntities.User.Role {
                    RoleName = GUEST_ROLE_NAME, DisplayName = "Guest", Description = "", SchoolId = null, Void = null
                },
                new DbEntities.User.Role {
                    RoleName = PARENT_ROLE_NAME, DisplayName = "Parent", Description = "", SchoolId = null, Void = null
                },
                new DbEntities.User.Role {
                    RoleName = NOTIFIER_ROLE_NAME, DisplayName = "Notifier", Description = "", SchoolId = null, Void = null
                },
                new DbEntities.User.Role {
                    RoleName = ORGANIZER_ROLE_NAME, DisplayName = "Organizer", Description = "", SchoolId = null, Void = null
                },
                new DbEntities.User.Role {
                    RoleName = ADMITTER_ROLE_NAME, DisplayName = "Admitter", Description = "Admitter is one who (can) admits users. Admitter is responsible to insert new students/teachers in the system", SchoolId = null, Void = null
                },
            };

            _context.Role.AddOrUpdate(
                p => p.RoleName,
                roles
                );
            _context.SaveChanges();
        }
예제 #13
0
        public void Seed()
        {
            var genders = new DbEntities.User.Gender[]
            {
                new DbEntities.User.Gender {
                    Name = "Male"
                },
                new DbEntities.User.Gender {
                    Name = "Female"
                },
                new DbEntities.User.Gender {
                    Name = "Rather not say"
                },
            };

            _context.Gender.AddOrUpdate(
                p => p.Name,
                genders
                );
            _context.SaveChanges();
        }
예제 #14
0
 public DbEntities.UserFile AddOrUpdateFolder(DbEntities.UserFile folder)
 {
     try
     {
         var ent = Context.File.Find(folder.Id);
         if (ent == null)
         {
             var saved = Context.File.Add(folder);
             Context.SaveChanges();
             return(saved);
         }
         ent.DisplayName  = folder.DisplayName;
         ent.ModifiedBy   = folder.ModifiedBy;
         ent.ModifiedDate = folder.ModifiedDate;
         ent.Void         = folder.Void;
         Context.SaveChanges();
         return(ent);
     }
     catch
     {
         return(null);
     }
 }
예제 #15
0
파일: UserSeeder.cs 프로젝트: skrishnau/LMS
        public void Seed()
        {
            var gender      = _context.Gender.First(x => x.Name == "Rather not say");
            var school      = _context.School.First(x => x.Code == SchoolSeeder.NEC_CODE);
            var adminRole   = _context.Role.First(x => x.RoleName == RoleSeeder.ADMIN_ROLE_NAME);
            var managerRole = _context.Role.First(x => x.RoleName == RoleSeeder.MANAGER_ROLE_NAME);
            var teacherRole = _context.Role.First(x => x.RoleName == RoleSeeder.TEACHER_ROLE_NAME);
            var studentRole = _context.Role.First(x => x.RoleName == RoleSeeder.STUDENT_ROLE_NAME);
            // var school = _context.School.FirstOrDefault(x => x.Code == SchoolSeeder.NEC_CODE);

            var users = new DbEntities.User.Users[]
            {
                new DbEntities.User.Users()
                {
                    UserName         = "******",
                    Password         = "******",
                    FirstName        = "Manager",
                    MiddleName       = "",
                    LastName         = "",
                    SchoolId         = school?.Id,//null,
                    GenderId         = gender.Id,
                    Email            = "",
                    DOB              = null,
                    IsActive         = true,
                    IsDeleted        = false,
                    Description      = "",
                    CreatedDate      = DateTime.Now,
                    Country          = "Nepal",
                    EmailDisplay     = "",
                    Phone            = "",
                    City             = "",
                    SecurityQuestion = "",
                    SecurityAnswer   = "",
                    UserRoles        = new List <DbEntities.User.UserRole>
                    {
                        new DbEntities.User.UserRole {
                            AssignedDate = DateTime.Now, RoleId = managerRole.Id
                        },
                        new DbEntities.User.UserRole {
                            AssignedDate = DateTime.Now, RoleId = adminRole.Id
                        },
                    },
                    UserImageId = null,
                    LastOnline  = null,
                },

                new DbEntities.User.Users()
                {
                    UserName         = "******",
                    Password         = "******",
                    FirstName        = "Teacher",
                    MiddleName       = "",
                    LastName         = "",
                    SchoolId         = school?.Id,//null,
                    GenderId         = gender.Id,
                    Email            = "",
                    DOB              = null,
                    IsActive         = true,
                    IsDeleted        = false,
                    Description      = "",
                    CreatedDate      = DateTime.Now,
                    Country          = "Nepal",
                    EmailDisplay     = "",
                    Phone            = "",
                    City             = "",
                    SecurityQuestion = "",
                    SecurityAnswer   = "",
                    UserRoles        = new List <DbEntities.User.UserRole>
                    {
                        new DbEntities.User.UserRole {
                            AssignedDate = DateTime.Now, RoleId = teacherRole.Id
                        },
                    },
                    UserImageId = null,
                    LastOnline  = null,
                },

                new DbEntities.User.Users()
                {
                    UserName         = "******",
                    Password         = "******",
                    FirstName        = "Student",
                    MiddleName       = "",
                    LastName         = "",
                    SchoolId         = school?.Id,//null,
                    GenderId         = gender.Id,
                    Email            = "",
                    DOB              = null,
                    IsActive         = true,
                    IsDeleted        = false,
                    Description      = "",
                    CreatedDate      = DateTime.Now,
                    Country          = "Nepal",
                    EmailDisplay     = "",
                    Phone            = "",
                    City             = "",
                    SecurityQuestion = "",
                    SecurityAnswer   = "",
                    UserRoles        = new List <DbEntities.User.UserRole>
                    {
                        new DbEntities.User.UserRole {
                            AssignedDate = DateTime.Now, RoleId = studentRole.Id
                        },
                    },
                    UserImageId = null,
                    LastOnline  = null,
                },
            };

            _context.Users.AddOrUpdate(
                p => p.UserName,
                users
                );
            _context.SaveChanges();
        }
예제 #16
0
        public void Seed()
        {
            var school                = _context.School.First(x => x.Code == SchoolSeeder.NEC_CODE);
            var managerRole           = _context.Role.First(x => x.RoleName == RoleSeeder.MANAGER_ROLE_NAME);
            var manager               = _context.Users.First(x => x.UserRoles.Any(y => y.RoleId == managerRole.Id));
            var programmingInCSubject = _context.Subject.First(x => x.Code == CourseSeeder.PROGRAMMING_IN_C_CODE);

            var programs = new DbEntities.Structure.Program[]
            {
                new DbEntities.Structure.Program {
                    Name        = COMPUTER_PROGRAM_NAME,
                    SchoolId    = school.Id,
                    Description = "",
                    CreatedDate = DateTime.Now,
                    Year        = new List <DbEntities.Structure.Year>
                    {
                        new DbEntities.Structure.Year {
                            Name        = "Year 1",
                            Description = "",
                            CreatedDate = DateTime.Now,
                            Position    = 1,
                            // SubjectStructures = new List<DbEntities.Subjects.SubjectStructure>(),
                            SubYears = new List <DbEntities.Structure.SubYear>
                            {
                                new DbEntities.Structure.SubYear {
                                    Position    = 1,
                                    Name        = "Sem I",
                                    Description = "", CreatedDate = DateTime.Now,
                                },
                                new DbEntities.Structure.SubYear {
                                    Position = 2, Name = "Sem II", Description = "", CreatedDate = DateTime.Now,
                                },
                            },
                        },
                        new DbEntities.Structure.Year {
                            Name        = "Year 2",
                            Description = "",
                            CreatedDate = DateTime.Now,
                            Position    = 2,
                            // SubjectStructures = new List<DbEntities.Subjects.SubjectStructure>(),
                            SubYears = new List <DbEntities.Structure.SubYear>
                            {
                                new DbEntities.Structure.SubYear {
                                    Position = 1, Name = "Sem III", Description = "", CreatedDate = DateTime.Now,
                                },
                                new DbEntities.Structure.SubYear {
                                    Position = 2, Name = "Sem IV", Description = "", CreatedDate = DateTime.Now,
                                },
                            }
                        },
                        new DbEntities.Structure.Year {
                            Name        = "Year 3",
                            Description = "",
                            CreatedDate = DateTime.Now,
                            Position    = 3,
                            // SubjectStructures = new List<DbEntities.Subjects.SubjectStructure>(),
                            SubYears = new List <DbEntities.Structure.SubYear>
                            {
                                new DbEntities.Structure.SubYear {
                                    Position = 1, Name = "Sem V", Description = "", CreatedDate = DateTime.Now,
                                },
                                new DbEntities.Structure.SubYear {
                                    Position = 2, Name = "Sem VI", Description = "", CreatedDate = DateTime.Now,
                                },
                            }
                        },
                        new DbEntities.Structure.Year {
                            Name        = "Year 4",
                            Description = "",
                            CreatedDate = DateTime.Now,
                            Position    = 4,
                            //  SubjectStructures = new List<DbEntities.Subjects.SubjectStructure>(),
                            SubYears = new List <DbEntities.Structure.SubYear>
                            {
                                new DbEntities.Structure.SubYear {
                                    Position = 1, Name = "Sem VII", Description = "", CreatedDate = DateTime.Now,
                                },
                                new DbEntities.Structure.SubYear {
                                    Position = 2, Name = "Sem VIII", Description = "", CreatedDate = DateTime.Now,
                                },
                            }
                        },
                    }
                },
            };

            _context.Program.AddOrUpdate(
                prop => prop.Name,
                programs
                );
            _context.SaveChanges();

            // subject Structure

            /*
             * SubjectStructures = new List<DbEntities.Subjects.SubjectStructure>
             *                      {
             *                          new DbEntities.Subjects.SubjectStructure{ Year =  SubjectId = programmingInCSubject.Id, Credit = 3, CreatedDate = DateTime.Now, IsElective = false, CreatedBy = manager.Id}
             *                      },
             */
        }
예제 #17
0
            public DbEntities.Office.School AddOrUpdateSchool(DbEntities.Office.School school, UserFile image)//System.Web.HttpPostedFile httpPostedFile
            {
                try
                {
                    using (var scope = new TransactionScope())
                    {
                        int earlierSchoolId = school.Id;
                        var ent             = Context.School.Find(school.Id);
                        if (ent == null)
                        {
                            var img = Context.File.Add(image);
                            Context.SaveChanges();
                            school.ImageId = img.Id;
                            ent            = Context.School.Add(school);
                            Context.SaveChanges();

                            //if this is newly created school (by the user) then add schoolId to the user
                            if (earlierSchoolId <= 0 && school.UserId > 0)
                            {
                                var user = Context.Users.Find(school.UserId);
                                if (user != null)
                                {
                                    user.SchoolId = ent.Id;
                                    Context.SaveChanges();
                                }
                            }
                        }
                        else
                        {
                            //update later
                            if (ent.ImageId <= 0)
                            {
                                //var cntx = new AcademicContext();
                                var img = Context.File.Add(image);
                                Context.SaveChanges();
                                school.ImageId = img.Id;
                                //school.ImageId = img.Id;

                                //ent.ImageId = img.Id;
                                //Context.Dispose();
                            }
                            else
                            {
                                var img = Context.File.Find(ent.ImageId);
                                if (img != null)
                                {
                                    img.DisplayName   = image.DisplayName;
                                    img.FileName      = image.FileName;
                                    img.ModifiedBy    = image.ModifiedBy;
                                    img.ModifiedDate  = image.ModifiedDate;
                                    img.FileDirectory = image.FileDirectory;

                                    img.FileSizeInBytes = image.FileSizeInBytes;
                                    img.FileType        = image.FileType;
                                    img.IconPath        = image.IconPath;
                                    img.Void            = image.Void;
                                    //Context.SaveChanges();
                                }
                            }

                            ent.ImageId         = school.ImageId;
                            ent.Name            = school.Name;
                            ent.Description     = school.Description;
                            ent.EmailGeneral    = school.EmailGeneral;
                            ent.EmailMarketing  = school.EmailMarketing;
                            ent.EmailSupport    = school.EmailSupport;
                            ent.PhoneMain       = school.PhoneMain;
                            ent.PhoneAfterHours = school.PhoneAfterHours;
                            ent.Address         = school.Address;
                            ent.Website         = school.Website;
                            ent.Code            = school.Code;

                            //ent.Image = school.Image;
                            //ent.ImageType = school.ImageType;

                            ent.IsActive  = school.IsActive;
                            ent.IsDeleted = school.IsDeleted;
                            Context.SaveChanges();
                        }
                        scope.Complete();
                        return(ent);
                    }
                }
                catch (DbEntityValidationException ex)
                {
                    throw ex;
                }
                catch (Exception)
                {
                    return(null);
                }
            }
예제 #18
0
            //used
            /// <summary>
            /// Creates a role if it doesn't exits.. then returns the role
            /// </summary>
            /// <param name="roleName"></param>
            /// <returns></returns>
            public Role GetRole(string roleName)
            {
                var role = Context.Role.FirstOrDefault(x => x.RoleName.ToLower().Equals(roleName.ToLower()));

                if (role == null)
                {
                    role = Context.Role.Add(new Role()
                    {
                        Description = "---add your description for '" + roleName + "' later---",
                        DisplayName = char.ToUpper(roleName[0]) + roleName.Substring(1, roleName.Length - 1),
                        RoleName    = roleName,
                        Void        = false,
                    });
                    Context.SaveChanges();
                }
                return(role);
            }
예제 #19
0
            public DbEntities.Structure.Year AddOrUpdateYear(DbEntities.Structure.Year year, List <SubYear> subYears)
            {
                try
                {
                    var ent = Context.Year.Find(year.Id);
                    if (ent == null)
                    {
                        var saved = Context.Year.Add(year);
                        Context.SaveChanges();

                        foreach (var sem in subYears)
                        {
                            sem.YearId = saved.Id;
                            Context.SubYear.Add(sem);
                            Context.SaveChanges();
                        }

                        return(saved);
                    }
                    else
                    {
                        ent.Name        = year.Name;
                        ent.ProgramId   = year.ProgramId;
                        ent.Description = year.Description;
                        ent.Position    = year.Position;

                        Context.SaveChanges();


                        foreach (var subYear in subYears)
                        {
                            var semFound = Context.SubYear.Find(subYear.Id);
                            if (semFound == null)
                            {
                                subYear.YearId = ent.Id;
                                Context.SubYear.Add(subYear);
                            }
                            else
                            {
                                semFound.Name = subYear.Name;
                            }
                            Context.SaveChanges();
                        }

                        return(ent);
                    }
                }
                catch
                {
                    return(null);
                }
            }
예제 #20
0
        public void Seed()
        {
            var school = _context.School.First(x => x.Code == SchoolSeeder.NEC_CODE);
            var admin  = _context.Users.First(x => x.UserRoles.Any(y => y.Role.RoleName == RoleSeeder.ADMIN_ROLE_NAME));

            // Links Resource
            #region Links Resources Save


            var usefulLinkUrlRes = new DbEntities.ActivityAndResource.UrlResource {
                Name = "Useful Links", Url = "https://www.google.com/search?source=hp&ei=4ugeXr22MKTdz7sPjveQoAI&q=C+programming&oq=C+programming&gs_l=psy-ab.3...75.1052..1770...0.0..0.0.0.......0....1..gws-wiz.dKDQyd3RRaE&ved=0ahUKEwi9r7qosoXnAhWk7nMBHY47BCQQ4dUDCAY&uact=5", DisplayDescriptionOnPage = false, Display = 0, Description = "",
            };
            var wikipediaUrlRes = new DbEntities.ActivityAndResource.UrlResource {
                Name = "Wekipedia", Url = "https://en.wikipedia.org/wiki/C_(programming_language)", DisplayDescriptionOnPage = false, Display = 0, Description = "",
            };
            var mitUrlRes = new DbEntities.ActivityAndResource.UrlResource {
                Name = "MIT Course", Url = "https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-087-practical-programming-in-c-january-iap-2010/", DisplayDescriptionOnPage = false, Display = 0, Description = "",
            };
            var projectsUrlRes = new DbEntities.ActivityAndResource.UrlResource {
                Name = "Projects", Url = "https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-087-practical-programming-in-c-january-iap-2010/lecture-notes/", DisplayDescriptionOnPage = false, Display = 0, Description = "",
            };
            var examplesUrlRes = new DbEntities.ActivityAndResource.UrlResource {
                Name = "100+ C programming examples", Url = "https://www.studytonight.com/c/programs/", DisplayDescriptionOnPage = true, Display = 0, Description = "100+ C programs with explanation and detailed solution and output for practising and improving your coding skills",
            };

            _context.UrlResource.AddOrUpdate(
                p => p.Name,
                usefulLinkUrlRes,
                wikipediaUrlRes,
                mitUrlRes,
                projectsUrlRes,
                examplesUrlRes
                );

            #endregion

            #region Page Resource Save

            var cFunctionsPage = new DbEntities.ActivityAndResource.PageResource {
                Name = "Function in C", PageContent = "Control flow. Functions and modular programming. Variable scope. Static and global variables.", DisplayPageName = true, DisplayPageDescription = false, DisplayDescriptionOnPage = true, Description = "A function is a block of statements that performs a specific task... ",
            };
            var loopsPage = new DbEntities.ActivityAndResource.PageResource {
                Name = "Pointers", PageContent = "Pointers and memory addressing. Arrays and pointer arithmetic. Strings. Searching and sorting algorithms.", DisplayPageName = true, DisplayPageDescription = false, DisplayDescriptionOnPage = true, Description = "For and While loops in C",
            };
            var recursionPage = new DbEntities.ActivityAndResource.PageResource {
                Name = "Recursions", PageContent = "", DisplayPageName = true, DisplayPageDescription = false, DisplayDescriptionOnPage = true, Description = "Recursion in C : Fibonacci series",
            };

            _context.PageResource.AddOrUpdate(
                p => p.Name,
                cFunctionsPage,
                loopsPage,
                recursionPage);

            #endregion

            #region Book Resource Save

            var beginnersBook = new DbEntities.ActivityAndResource.BookResource
            {
                Name = "Beginners Book",
                ChapterFormatting             = 1,
                CustomTitles                  = false,
                Description                   = "The expert at anything was once a beginner – Helen Hayes",
                StyleOfNavigation             = 0,
                DisplayDescriptionOnCourePage = false,
                Chapters = new List <DbEntities.ActivityAndResource.BookItems.BookChapter>
                {
                    new DbEntities.ActivityAndResource.BookItems.BookChapter {
                        Position = 1, Title = "Turbo C++ Installation", Content = "<strong>Install Turbo C++: Step by Step Guide</strong>",
                    },
                    new DbEntities.ActivityAndResource.BookItems.BookChapter {
                        Position = 2, Title = "First C program", Content = "<strong>C Program Structure – First C Program</strong>",
                    },
                }
            };
            _context.BookResource.AddOrUpdate(p => p.Name, beginnersBook);
            #endregion

            // save all before
            _context.SaveChanges();

            // Course Categories with all the required course and course resources in one go
            var courseCategories = new Academic.DbEntities.Subjects.SubjectCategory[]
            {
                new DbEntities.Subjects.SubjectCategory {
                    Name        = "Computer",
                    Code        = "COMP",
                    CreatedDate = DateTime.Now,
                    Description = "",
                    IsActive    = true,
                    IsVoid      = false,
                    ParentId    = null,
                    SchoolId    = school.Id,
                    Subjects    = new List <DbEntities.Subjects.Subject>
                    {
                        new DbEntities.Subjects.Subject {
                            Code            = PROGRAMMING_IN_C_CODE, FullName = "Programming in C", ShortName = "C", Credit = 3, CreatedById = admin.Id, CreatedDate = DateTime.Now, Summary = "", Void = false,
                            SubjectSections = new List <DbEntities.Subjects.SubjectSection>
                            {
                                new DbEntities.Subjects.SubjectSection {
                                    Name = "Introduction", Position = 1, ShowSummary = true, Summary = GetProgrammingInCSummary(), Void = false
                                },
                                new DbEntities.Subjects.SubjectSection {
                                    Name = "Background information", Position = 2, ShowSummary = false, Summary = "", Void = false,
                                    ActivityResources = new List <DbEntities.ActivityAndResource.ActivityResource>
                                    {
                                        new DbEntities.ActivityAndResource.ActivityResource {
                                            Name = "Useful Links", ActivityResourceId = usefulLinkUrlRes.Id, ActivityOrResource = false, ActivityResourceType = ((int)Enums.Resources.Url) + 1, Position = 1, Void = false,
                                        },
                                        new DbEntities.ActivityAndResource.ActivityResource {
                                            Name = "Wikipedia", ActivityResourceId = wikipediaUrlRes.Id, ActivityOrResource = false, ActivityResourceType = ((int)Enums.Resources.Url) + 1, Position = 1, Void = false,
                                        },
                                        new DbEntities.ActivityAndResource.ActivityResource {
                                            Name = "MIT Courses", ActivityResourceId = mitUrlRes.Id, ActivityOrResource = false, ActivityResourceType = ((int)Enums.Resources.Url) + 1, Position = 1, Void = false,
                                        },
                                    }
                                },
                                new DbEntities.Subjects.SubjectSection {
                                    Name = "Understanding Basics", Position = 3, ShowSummary = false, Summary = "", Void = false,
                                    ActivityResources = new List <DbEntities.ActivityAndResource.ActivityResource>
                                    {
                                        new DbEntities.ActivityAndResource.ActivityResource {
                                            Name = "Beginners Book", ActivityResourceId = beginnersBook.Id, ActivityOrResource = false, ActivityResourceType = ((int)Enums.Resources.Book) + 1, Position = 1, Void = false,
                                        },
                                        new DbEntities.ActivityAndResource.ActivityResource {
                                            Name = "Functions", ActivityResourceId = cFunctionsPage.Id, ActivityOrResource = false, ActivityResourceType = ((int)Enums.Resources.Page) + 1, Position = 2, Void = false,
                                        },
                                        new DbEntities.ActivityAndResource.ActivityResource {
                                            Name = "Pointers", ActivityResourceId = loopsPage.Id, ActivityOrResource = false, ActivityResourceType = ((int)Enums.Resources.Page) + 1, Position = 3, Void = false,
                                        },
                                        new DbEntities.ActivityAndResource.ActivityResource {
                                            Name = "Recursion", ActivityResourceId = recursionPage.Id, ActivityOrResource = false, ActivityResourceType = ((int)Enums.Resources.Page) + 1, Position = 4, Void = false,
                                        },
                                    }
                                },
                                new DbEntities.Subjects.SubjectSection {
                                    Name = "Project examples", Position = 3, ShowSummary = false, Summary = "", Void = false,
                                    ActivityResources = new List <DbEntities.ActivityAndResource.ActivityResource>
                                    {
                                        new DbEntities.ActivityAndResource.ActivityResource {
                                            Name = "C Programming Examples", ActivityResourceId = examplesUrlRes.Id, ActivityOrResource = false, ActivityResourceType = ((int)Enums.Resources.Url) + 1, Position = 1, Void = false,
                                        },
                                        new DbEntities.ActivityAndResource.ActivityResource {
                                            Name = "Projects", ActivityResourceId = projectsUrlRes.Id, ActivityOrResource = false, ActivityResourceType = ((int)Enums.Resources.Url) + 1, Position = 2, Void = false,
                                        },
                                    }
                                },
                            }
                        },
                        //new DbEntities.Subjects.Subject{Code = "CMP-302", FullName = "Object Oriented Programming in C++", ShortName = "C++", Credit = 3, CreatedById = admin.Id, CreatedDate = DateTime.Now, Summary = "", Void = false},
                        //new DbEntities.Subjects.Subject{Code = "CMP-303", FullName = "Data Structure and Algorithms", ShortName = "DSA", Credit = 3, CreatedById = admin.Id, CreatedDate = DateTime.Now, Summary = "", Void = false},
                        //new DbEntities.Subjects.Subject{Code = "CMP-306", FullName = "Compiler Design", ShortName = "Compiler", Credit = 2, CreatedById = admin.Id, CreatedDate = DateTime.Now, Summary = "", Void = false},
                        //new DbEntities.Subjects.Subject{Code = "CMP-307", FullName = "Image Processing and Pattern Recognition", ShortName = "IPPR", Credit = 3, CreatedById = admin.Id, CreatedDate = DateTime.Now, Summary = "", Void = false},
                        //new DbEntities.Subjects.Subject{Code = "CMP-309", FullName = "Data Mining", ShortName = "DMine", Credit = 1, CreatedById = admin.Id, CreatedDate = DateTime.Now, Summary = "", Void = false},
                        //new DbEntities.Subjects.Subject{Code = "CMP-310", FullName = "Simulation", ShortName = "SIM", Credit = 3, CreatedById = admin.Id, CreatedDate = DateTime.Now, Summary = "", Void = false},
                    }
                },
                new DbEntities.Subjects.SubjectCategory {
                    Name        = "Electronics",
                    Code        = "ELX",
                    CreatedDate = DateTime.Now,
                    Description = "",
                    IsActive    = true,
                    IsVoid      = false,
                    ParentId    = null,
                    SchoolId    = school.Id,
                    Subjects    = new List <DbEntities.Subjects.Subject>
                    {
                        new DbEntities.Subjects.Subject {
                            Code = "ELX-201", FullName = "Logic Circuits", ShortName = "LC", Credit = 3, CreatedById = admin.Id, CreatedDate = DateTime.Now, Summary = "", Void = false
                        },
                        //new DbEntities.Subjects.Subject{Code = "ELX-202", FullName = "Microprocessors ", ShortName = "Microprocessors", Credit = 3, CreatedById = admin.Id, CreatedDate = DateTime.Now, Summary = "", Void = false},
                        //new DbEntities.Subjects.Subject{Code = "ELX-203", FullName = "Microcontrollers and Embeded Systems", ShortName = "Microcontrollers", Credit = 3, CreatedById = admin.Id, CreatedDate = DateTime.Now, Summary = "", Void = false},
                    }
                },
            };
            _context.SubjectCategory.AddOrUpdate(
                p => p.Name,
                courseCategories
                );
            _context.SaveChanges();
        }
예제 #21
0
            //public int[] GetInstSchool(int userId)
            //{
            //    var std = Context.Student.FirstOrDefault(x => x.Id == userId);
            //    if (std == null) return new int[]{0,0};
            //    var schoolId = std.SchoolId;
            //    var instId = std.School.InstitutionId;
            //    return new int[]{instId,schoolId};
            //}


            //public ViewModel.SystemControl.Office.InstitutionAndSchool GetInstitutionAndSchool(int userId)
            //{
            //    var teach = Context.Student.Include(x=>x.School).FirstOrDefault(x => x.Id == userId);
            //    if (teach == null) return null;
            //    var model = new InstitutionAndSchool();
            //    model.School = teach.School;
            //    var inst = Context.Institution.Find(teach.School.InstitutionId);
            //    if (inst != null)
            //        model.Institution = inst;
            //    return model;
            //}

            public bool AddOrUpdateStudents(List <DbEntities.User.Users> users,
                                            List <DbEntities.Students.Student> students, int programBatchId = 0)
            {
                using (var scope = new TransactionScope())
                {
                    for (int i = 0; i < users.Count; i++)
                    {
                        var user    = users[i];
                        var student = students[i];

                        var prev = Context.Users.Find(user.Id);
                        if (prev == null)
                        {
                            //user.FirstName = user.FirstName;
                            //user.LastName = user.LastName.Trim();
                            prev = Context.Users.Add(user);
                            Context.SaveChanges();
                            if (prev != null)
                            {
                                student.UserId = prev.Id;
                                student.Name   = prev.FullName;
                                var std = Context.Student.Add(student);
                                Context.SaveChanges();
                                if (std != null)
                                {
                                    var role = Context.Role.FirstOrDefault(x => x.RoleName == "student");
                                    if (role != null)
                                    {
                                        var userRole = new UserRole()
                                        {
                                            AssignedDate = DateTime.Now
                                            ,
                                            RoleId = role.Id
                                            ,
                                            UserId = prev.Id
                                        };
                                        Context.UserRole.Add(userRole);
                                        Context.SaveChanges();
                                    }
                                    if (programBatchId > 0)
                                    {
                                        var stdBatch = new DbEntities.Batches.StudentBatch()
                                        {
                                            ProgramBatchId = programBatchId
                                            ,
                                            StudentId = std.Id
                                            ,
                                            AddedDate = DateTime.Now
                                        };
                                        Context.StudentBatch.Add(stdBatch);
                                        Context.SaveChanges();
                                    }
                                }
                            }
                        }
                        else
                        {
                            prev.CreatedDate = user.CreatedDate;
                            prev.DOB         = user.DOB;
                            prev.FirstName   = user.FirstName;

                            prev.SchoolId = user.SchoolId;
                            prev.City     = user.City;
                            prev.Country  = user.Country;
                            prev.Email    = user.Email;
                            prev.UserName = user.UserName;

                            prev.Password  = user.Password;
                            prev.LastName  = user.LastName;
                            prev.IsActive  = user.IsActive;
                            prev.IsDeleted = user.IsDeleted;

                            var std = Context.Student.Find(student.Id);
                            if (std == null)
                            {
                                student.UserId = prev.Id;
                                Context.Student.Add(student);
                            }

                            Context.SaveChanges();
                        }
                    }
                    scope.Complete();
                    return(true);
                }
                return(false);
            }
예제 #22
0
            //
            public DbEntities.Grades.Grade AddOrUpdateGrade(DbEntities.Grades.Grade grade,
                                                            List <DbEntities.Grades.GradeValue> gradeValuesList)
            {
                try
                {
                    using (var scope = new TransactionScope())
                    {
                        var ent = Context.Grade.Find(grade.Id);
                        if (ent == null)
                        {
                            ent = Context.Grade.Add(grade);
                            Context.SaveChanges();
                            if (gradeValuesList != null)
                            {
                                for (var i = 0; i < gradeValuesList.Count; i++) // in gradeValuesList)
                                {
                                    gradeValuesList[i].GradeId = ent.Id;
                                    Context.GradeValue.Add(gradeValuesList[i]);
                                    Context.SaveChanges();
                                }
                            }
                        }
                        else
                        {
                            ent.Name        = grade.Name;
                            ent.Description = grade.Description;
                            ent.GradeValueIsInPercentOrPostition = grade.GradeValueIsInPercentOrPostition;
                            ent.RangeOrValue = grade.RangeOrValue;
                            if (!grade.RangeOrValue)//range
                            {
                                ent.MinimumPassValue = grade.MinimumPassValue;
                                ent.TotalMaxValue    = grade.TotalMaxValue;
                                ent.TotalMinValue    = grade.TotalMinValue;

                                Context.SaveChanges();
                            }
                            else//values
                            {
                                ent.GradeValueIsInPercentOrPostition = grade.GradeValueIsInPercentOrPostition;
                                ent.MinimumPassValue = grade.MinimumPassValue;
                                ent.TotalMaxValue    = grade.TotalMaxValue;
                                ent.TotalMinValue    = grade.TotalMinValue;

                                //var olderlist = Context.GradeValue.Where(x => x.GradeId == ent.Id).ToList();

                                //for (int i = 0; i < olderlist.Count; i++)
                                //{
                                //    Context.GradeValue.Remove(olderlist[i]);
                                //}
                                //Context.SaveChanges();

                                if (gradeValuesList != null)
                                {
                                    foreach (var gv in gradeValuesList)
                                    {
                                        var gvDb = Context.GradeValue.Find(gv.Id);
                                        if (gvDb == null)
                                        {
                                            gv.GradeId = ent.Id;
                                            Context.GradeValue.Add(gv);
                                            Context.SaveChanges();
                                        }
                                        else
                                        {
                                            gvDb.Void  = gv.Void;
                                            gvDb.Value = gv.Value;
                                            gvDb.EquivalentPercentOrPostition = gv.EquivalentPercentOrPostition;
                                            gvDb.IsFailGrade = gv.IsFailGrade;
                                            Context.SaveChanges();
                                        }
                                    }
                                }
                            }
                            Context.SaveChanges();
                        }
                        scope.Complete();
                        return(ent);
                    }
                }
                catch
                {
                    return(null);
                }
            }
예제 #23
0
            //used
            public string MarkCompleteAcademicYearSession(int userId, int aId, int sId)
            {
                try
                {
                    var date = DateTime.Now;
                    using (var scope = new TransactionScope())
                    {
                        var a = Context.AcademicYear.Find(aId);
                        var s = Context.Session.Find(sId);

                        if (a != null)
                        {
                            var rc = Context.RunningClass.Where(x => x.AcademicYearId == a.Id);
                            foreach (var r in rc)
                            {
                                r.Completed = true;
                                foreach (var sc in Context.SubjectClass.Where(w => w.RunningClassId == r.Id))
                                {
                                    sc.SessionComplete        = true;
                                    sc.CompleteMarkedByUserId = userId;
                                    sc.CompletionMarkedDate   = date;
                                    Context.SaveChanges();
                                }
                            }
                            a.Completed = true;
                            a.IsActive  = false;

                            foreach (var se in a.Sessions.Where(x => x.IsActive))
                            {
                                se.IsActive  = false;
                                se.Completed = true;
                            }

                            Context.SaveChanges();
                        }
                        else if (s != null)
                        {
                            var rc = Context.RunningClass.Where(x => x.SessionId == s.Id);
                            foreach (var r in rc)
                            {
                                r.Completed = true;
                                foreach (var sc in Context.SubjectClass.Where(w => w.RunningClassId == r.Id))
                                {
                                    sc.SessionComplete        = true;
                                    sc.CompleteMarkedByUserId = userId;
                                    sc.CompletionMarkedDate   = date;
                                    Context.SaveChanges();
                                }
                            }
                            s.Completed = true;
                            s.IsActive  = false;
                            Context.SaveChanges();
                        }
                        else
                        {
                            return("Go to List.");
                        }


                        scope.Complete();
                        return("success");
                    }
                }
                catch
                {
                    return("Error while saving.");
                }
            }
예제 #24
0
            public DbEntities.Exams.Exam AddOrUpdateExam(DbEntities.Exams.Exam exam
                                                         , int userId, List <ExamOfClass> eocList, string titleOfNotice)
            {
                try
                {
                    using (var scope = new TransactionScope())
                    {
                        var model = Context.Exam.Find(exam.Id);
                        if (model == null)
                        {
                            model = Context.Exam.Add(exam);
                            Context.SaveChanges();
                        }
                        else
                        {
                            model.Name                       = exam.Name;
                            model.NoticeContent              = exam.NoticeContent;
                            model.ResultDate                 = exam.ResultDate;
                            model.StartDate                  = exam.StartDate;
                            model.Weight                     = exam.Weight;
                            model.ExamTypeId                 = exam.ExamTypeId;
                            model.UpdatedDate                = DateTime.Now;
                            model.ExamCoordinatorId          = exam.ExamCoordinatorId;
                            model.PublishNoticeToNoticeBoard = exam.PublishNoticeToNoticeBoard;
                            Context.SaveChanges();
                        }

                        //publishing notice to noticeBoard
                        var notice = Context.Notice.Find(model.NoticeId ?? 0);
                        if (notice == null)
                        {
                            var n = new DbEntities.Notices.Notice()
                            {
                                PublishNoticeToNoticeBoard = model.PublishNoticeToNoticeBoard ?? false
                                ,
                                Content = model.NoticeContent
                                ,
                                CreatedBy = userId
                                ,
                                CreatedDate = DateTime.Now
                                ,
                                NoticePublishTo = true
                                , SchoolId      = model.SchoolId
                            };

                            if (model.PublishNoticeToNoticeBoard ?? false)
                            {
                                n.PublishedDate = DateTime.Now;
                                n.Title         = titleOfNotice;
                            }
                            else
                            {
                                n.Title = model.ExamTypeId == null ? model.Name : model.ExamType.Name;
                            }

                            var savedNotice = Context.Notice.Add(n);
                            Context.SaveChanges();

                            model.NoticeId = savedNotice.Id;
                            Context.SaveChanges();
                        }
                        else
                        {
                            if (model.PublishNoticeToNoticeBoard ?? false)
                            {
                                notice.Title = titleOfNotice;
                                if (!notice.PublishNoticeToNoticeBoard)
                                {
                                    notice.PublishedDate = DateTime.Now;
                                }
                            }
                            else
                            {
                                notice.Title = model.ExamTypeId == null ? model.Name : model.ExamType.Name;
                            }
                            notice.PublishNoticeToNoticeBoard = model.PublishNoticeToNoticeBoard ?? false;

                            notice.Content         = model.NoticeContent;
                            notice.UpdatedBy       = userId;
                            notice.UpdatedDate     = DateTime.Now;
                            notice.NoticePublishTo = true;

                            Context.SaveChanges();
                        }

                        if (eocList != null)//&& userId != null
                        {
                            eocList.ForEach(x =>
                            {
                                x.ExamId = model.Id;
                                var eoc  = Context.ExamOfClass.Find(x.Id);
                                if (eoc == null)
                                {
                                    eoc = x; //
                                    // eoc.SettingsUsedFromExam = true;
                                    eoc.CreatedBy   = userId;
                                    eoc.CreatedDate = DateTime.Now;

                                    var addedClass = Context.ExamOfClass.Add(eoc);
                                    Context.SaveChanges();

                                    //now add all the subjects //needed only here
                                    //while updating the subjects need not be changed
                                    var subjects = Context.SubjectClass.Where(sc =>
                                                                              sc.RunningClassId == eoc.RunningClassId &&
                                                                              sc.IsRegular &&
                                                                              !(sc.Void ?? false));
                                    foreach (var sc in subjects)
                                    {
                                        Context.ExamSubject.Add(new ExamSubject()
                                        {
                                            ExamOfClassId = addedClass.Id
                                            ,
                                            SubjectClassId = sc.Id
                                            ,
                                            SettingsUsedFromExam = true
                                            ,
                                        });
                                        Context.SaveChanges();
                                    }
                                }
                                else
                                {
                                    eoc.Void        = x.Void;
                                    eoc.UpdatedBy   = x.UpdatedBy;
                                    eoc.UpdatedDate = x.UpdatedDate;
                                    //eoc.Weight = x.Weight;
                                    //eoc.SettingsUsedFromExam = x.SettingsUsedFromExam;
                                    //eoc.PassMarks = x.PassMarks;
                                    //eoc.IsPercent = x.IsPercent;
                                    //eoc.FullMarks = x.FullMarks;

                                    Context.SaveChanges();
                                }
                            });
                        }
                        scope.Complete();

                        return(model);
                    }
                }
                catch (Exception ex)
                {
                    return(null);
                }
            }