コード例 #1
0
        public static void MarkAllConvosAsRead(string userId, string otherUserId)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    var msgs = (from a in context.PrivateMessages
                                where (a.FromUser == userId && a.ToUser == otherUserId) || (a.FromUser == otherUserId && a.ToUser == userId)
                                select a).ToList();

                    foreach (var pm in msgs)
                    {
                        if (pm.DateRead == null && pm.FromUser != userId)
                        {
                            pm.DateRead             = DateTime.Now;
                            context.Entry(pm).State = EntityState.Modified;
                        }
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        public static void AddEndDate(string Id, DateTime endDate)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    if (GetUser(Id) == null)
                    {
                        throw new Exception("User was not edited.  User ID not found.");
                    }
                    else
                    {
                        var user = GetUser(Id);

                        user.EndDate = endDate;
                        context.Entry(user).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
        public static void SetGrade(string studentId, int sectionId, int markingPeriodId, string grade)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    var enroll = (from a in context.Enrollments where a.UserId == studentId && a.SectionId == sectionId && a.MarkingPeriodId == markingPeriodId select a).FirstOrDefault();

                    if (enroll != null)
                    {
                        enroll.GradeValue           = grade;
                        context.Entry(enroll).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                    }
                    else
                    {
                        throw new Exception("Enrollment not found.  Grade not set.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #4
0
        public static void RemoveGrade(string studentId, int schoolId, int subjectId, int classId,
                                       int sectionId, int markingPeriodId)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    var enroll = GetEnrollment(studentId, schoolId, subjectId, classId, sectionId, markingPeriodId);

                    if (enroll != null)
                    {
                        enroll.GradeValue           = null;
                        context.Entry(enroll).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                    }
                    else
                    {
                        throw new Exception("Enrollment not found.  Grade not set.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #5
0
        public static void UpdateTimeSlot(int schoolId, TimeSpan start, TimeSpan end, int id)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    if ((from a in context.TimeSlots where a.TimeSlotId == id select a) == null)
                    {
                        throw new Exception("Time slot could not be found");
                    }

                    if ((from a in context.TimeSlots where a.StartTime == start && a.EndTime == end && a.SchoolId == schoolId && a.TimeSlotId != id select a).FirstOrDefault() != null)
                    {
                        throw new Exception("Time slot already exists.  Time slot not updated.");
                    }

                    TimeSlot ts = (from a in context.TimeSlots where a.TimeSlotId == id select a).FirstOrDefault();
                    ts.StartTime = start;
                    ts.EndTime   = end;

                    context.Entry(ts).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #6
0
        public static void UpdateUserCred(string id, string username, string password)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    var cred = GetUserCred(id);

                    if (cred == null)
                    {
                        throw new Exception("User Credentials could not be found.");
                    }

                    if (DoesUsernameExist(username, id))
                    {
                        throw new Exception("Username already exists.  Please select another.");
                    }

                    cred.UserName = username;

                    if (password != null)
                    {
                        cred.Password = GetSHA256Hash(password);
                    }

                    context.Entry(cred).State = System.Data.Entity.EntityState.Modified;

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #7
0
        private static void CreateEditMarkingPeriod(string op, int?markingPeriodId, string period, bool fullYear, int schoolYearId, DateTime start, DateTime end)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    if (op.Equals("ADD"))
                    {
                        if ((from a in context.MarkingPeriods where a.Period == period && a.FullYear == fullYear && a.SchoolYearId == schoolYearId select a).FirstOrDefault() != null)
                        {
                            throw new Exception("Marking period was not created.  Marking period already exists for this school year.");
                        }

                        MarkingPeriod MarkingPeriod = new MarkingPeriod()
                        {
                            SchoolYear = (from a in context.SchoolYears where a.SchoolYearId == schoolYearId select a).FirstOrDefault(),
                            Period     = fullYear ? null : period,
                            FullYear   = fullYear,
                            StartDate  = start,
                            EndDate    = end
                        };

                        context.MarkingPeriods.Add(MarkingPeriod);
                        context.SaveChanges();
                    }
                    else if (op.Equals("EDIT"))
                    {
                        var mPeriod = (from a in context.MarkingPeriods where a.MarkingPeriodId == markingPeriodId.Value select a).FirstOrDefault();

                        if (mPeriod == null)
                        {
                            throw new Exception("Marking period was not updated.  Marking period not found.");
                        }

                        if (GetMarkingPeriod(period, fullYear, schoolYearId, markingPeriodId.Value, context) != null)
                        {
                            throw new Exception("Marking period was not updated.  New marking period values already exist.");
                        }

                        mPeriod.Period     = fullYear ? null : period;
                        mPeriod.FullYear   = fullYear;
                        mPeriod.StartDate  = start;
                        mPeriod.EndDate    = end;
                        mPeriod.SchoolYear = (from a in context.SchoolYears where a.SchoolYearId == schoolYearId select a).FirstOrDefault();

                        context.Entry(mPeriod).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #8
0
        private static void CreateEditSchoolYear(string op, int schoolId, string year, DateTime start, DateTime end, int?schoolYearId)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    if (op.Equals("ADD"))
                    {
                        if ((from a in context.SchoolYears where a.Year == year select a).FirstOrDefault() != null)
                        {
                            throw new Exception("School year was not created.  School year already exists for this school.");
                        }
                        else
                        {
                            SchoolYear schoolyear = new SchoolYear()
                            {
                                School    = (from a in context.Schools where a.SchoolId == schoolId select a).FirstOrDefault(),
                                Year      = year,
                                StartDate = start,
                                EndDate   = end
                            };

                            context.SchoolYears.Add(schoolyear);
                            context.SaveChanges();
                        }
                    }
                    else if (op.Equals("EDIT"))
                    {
                        if ((from a in context.SchoolYears where a.SchoolYearId == schoolYearId.Value select a).FirstOrDefault() == null)
                        {
                            throw new Exception("Subject was not updated.  Subject name not found.");
                        }
                        else if ((from a in context.SchoolYears where a.SchoolYearId != schoolYearId.Value && a.SchoolId == schoolId && a.Year == year select a).FirstOrDefault() != null)
                        {
                            throw new Exception("Subject was not updated.  New subject name already exists in database.");
                        }
                        else
                        {
                            var schYear = (from a in context.SchoolYears where a.SchoolYearId == schoolYearId.Value select a).FirstOrDefault();

                            schYear.Year                 = year;
                            schYear.StartDate            = start;
                            schYear.EndDate              = end;
                            context.Entry(schYear).State = System.Data.Entity.EntityState.Modified;
                            context.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #9
0
        private static void CreateEditClass(string op, int schoolId, int subjectId, int?classId, string description, string className)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    if (op.Equals("ADD"))
                    {
                        if ((from a in context.Classes where a.ClassName == className && a.SchoolId == schoolId && a.SubjectId == subjectId select a).FirstOrDefault() != null)
                        {
                            throw new Exception("Class was not created.  Class name already exists for this school/subject.");
                        }
                        else
                        {
                            Class Class = new Class()
                            {
                                ClassName   = className,
                                Subject     = (from a in context.Subjects where a.SubjectId == subjectId select a).FirstOrDefault(),
                                Description = string.IsNullOrWhiteSpace(description) ? null : description
                            };

                            context.Classes.Add(Class);
                            context.SaveChanges();
                        }
                    }
                    else if (op.Equals("EDIT"))
                    {
                        var mClass = (from a in context.Classes where a.ClassId == classId.Value select a).FirstOrDefault();

                        if (mClass == null)
                        {
                            throw new Exception("Class was not updated.  Class name not found.");
                        }

                        if ((from a in context.Classes where a.ClassName == className && a.SubjectId == mClass.SubjectId && a.ClassId != classId.Value select a).FirstOrDefault() != null)
                        {
                            throw new Exception("Class was not updated.  Class name already exists for subject/school.");
                        }

                        mClass.ClassName   = className;
                        mClass.Subject     = (from a in context.Subjects where a.SubjectId == subjectId select a).FirstOrDefault();
                        mClass.Description = string.IsNullOrWhiteSpace(description) ? null : description;

                        context.Entry(mClass).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #10
0
        private static void CreateEditClub(string op, int?schoolId, string clubName, string description, int?clubId)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    if (op.Equals("ADD"))
                    {
                        if ((from a in context.Clubs where a.SchoolId == schoolId.Value && a.ClubName == clubName select a).FirstOrDefault() != null)
                        {
                            throw new Exception("Club was not created.  Club name already exists for this school.");
                        }
                        else
                        {
                            Club Club = new Club()
                            {
                                School      = (from a in context.Schools where a.SchoolId == schoolId select a).FirstOrDefault(),
                                Description = !string.IsNullOrWhiteSpace(description) ? description : null,
                                ClubName    = clubName
                            };

                            context.Clubs.Add(Club);
                            context.SaveChanges();
                        }
                    }
                    else if (op.Equals("EDIT"))
                    {
                        if ((from a in context.Clubs where a.ClubId == clubId.Value select a).FirstOrDefault() == null)
                        {
                            throw new Exception("Club was not updated.  Club not found.");
                        }
                        else if ((from a in context.Clubs where a.ClubId != clubId.Value && a.SchoolId == schoolId.Value && a.ClubName == clubName select a).FirstOrDefault() != null)
                        {
                            throw new Exception("Club was not updated.  New club name already exists in database.");
                        }
                        else
                        {
                            var Club = (from a in context.Clubs where a.ClubId == clubId select a).FirstOrDefault();

                            Club.ClubName             = clubName;
                            Club.Description          = !string.IsNullOrWhiteSpace(description) ? description : null;
                            context.Entry(Club).State = System.Data.Entity.EntityState.Modified;
                            context.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #11
0
        private static void CreateEditSubject(string op, int?schoolId, string subjName, int?subjectId)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    if (op.Equals("ADD"))
                    {
                        if ((from a in context.Subjects where a.SchoolId == schoolId.Value && a.SubjectName == subjName select a).FirstOrDefault() != null)
                        {
                            throw new Exception("Subject was not created.  Subject name already exists for this school.");
                        }
                        else
                        {
                            Subject subject = new Subject()
                            {
                                School      = (from a in context.Schools where a.SchoolId == schoolId.Value select a).FirstOrDefault(),
                                SubjectName = subjName
                            };

                            context.Subjects.Add(subject);
                            context.SaveChanges();
                        }
                    }
                    else if (op.Equals("EDIT"))
                    {
                        if ((from a in context.Subjects where a.SubjectId == subjectId.Value select a).FirstOrDefault() == null)
                        {
                            throw new Exception("Subject was not updated.  Subject name not found.");
                        }
                        else if ((from a in context.Subjects where a.SchoolId == schoolId && a.SubjectName == subjName && a.SubjectId != subjectId.Value select a).FirstOrDefault() != null)
                        {
                            throw new Exception("Subject was not updated.  New subject name already exists in database.");
                        }
                        else
                        {
                            var subject = (from a in context.Subjects where a.SubjectId == subjectId select a).FirstOrDefault();

                            subject.SubjectName          = subjName;
                            context.Entry(subject).State = System.Data.Entity.EntityState.Modified;
                            context.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #12
0
        public static void UpdateGender(string gType, string newValue)
        {
            using (SmacEntities context = new SmacEntities())
            {
                Gender gender = (from a in context.Genders where a.GenderType == gType select a).FirstOrDefault();

                if (gender != null)
                {
                    gender.GenderType           = newValue;
                    context.Entry(gender).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                }
            }
        }
コード例 #13
0
        private static void CreateEditSection(string op, int schoolId, int subjectId, int classId, int?sectionId, string sectionName, string description)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    if (op.Equals("ADD"))
                    {
                        if ((from a in context.Sections where a.SchoolId == schoolId && a.SubjectId == subjectId && a.ClassId == classId && a.SectionName == sectionName select a).FirstOrDefault() != null)
                        {
                            throw new Exception("Section was not created.  Section name already exists for this school/subject/class.");
                        }
                        else
                        {
                            Section section = new Section()
                            {
                                Class       = (from a in context.Classes where a.ClassId == classId select a).FirstOrDefault(),
                                SectionName = sectionName,
                                Description = description
                            };

                            context.Sections.Add(section);
                            context.SaveChanges();
                        }
                    }
                    else if (op.Equals("EDIT"))
                    {
                        var mSection = (from a in context.Sections where a.SectionId == sectionId.Value select a).FirstOrDefault();
                        if (mSection == null)
                        {
                            throw new Exception("Section was not updated.  Section name not found.");
                        }

                        if ((from a in context.Sections where a.SchoolId == schoolId && a.SubjectId == subjectId && a.ClassId == classId && a.SectionName == sectionName && a.SectionId != sectionId.Value select a).FirstOrDefault() != null)
                        {
                            throw new Exception("Section was not created as it already exists for this school/subject/class.");
                        }

                        mSection.SectionName          = sectionName;
                        mSection.Description          = description;
                        context.Entry(mSection).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #14
0
 public static void UpdateThread(int threadId, string content)
 {
     try
     {
         using (SmacEntities context = new SmacEntities())
         {
             var thread = GetThread(threadId);
             thread.Content = content;
             context.Entry(thread).State = System.Data.Entity.EntityState.Modified;
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #15
0
        private static void CreateEditSchool(string op, string schName, string addr, string city, string state, string zip, string phone, int?schoolId)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    if (op.Equals("ADD"))
                    {
                        School school = new School()
                        {
                            SchoolName    = schName,
                            StreetAddress = addr,
                            City          = city,
                            State         = state,
                            ZipCode       = zip,
                            PhoneNumber   = phone
                        };

                        context.Schools.Add(school);
                        context.SaveChanges();
                    }
                    else if (op.Equals("EDIT"))
                    {
                        var school = GetSchool(schoolId.Value);

                        school.SchoolName           = schName;
                        school.StreetAddress        = addr;
                        school.City                 = city;
                        school.State                = state;
                        school.ZipCode              = zip;
                        school.PhoneNumber          = phone;
                        context.Entry(school).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #16
0
        public static void UpdateLatestNews(int newsId, string news, string userId)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    var ln = (from a in context.LatestNewsSet where a.LatestNewsId == newsId select a).FirstOrDefault();

                    ln.Content  = news;
                    ln.PostedAt = DateTime.Now;
                    ln.User     = (from a in context.Users where a.UserId == userId select a).FirstOrDefault();

                    context.Entry(ln).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #17
0
        public static void SetLastLoggedOut(string Id, DateTime?newVal)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    var user = (from a in context.Users where a.UserId == Id select a).FirstOrDefault();

                    if (user != null)
                    {
                        user.LastLoggedOut        = newVal;
                        context.Entry(user).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #18
0
        private static void CreateEditUser(string op, string Id, string newId, string fName, string mName, string lName, string email, string phone, string gender, bool?isActive, string userName, string password, DateTime?startDate, DateTime?endDate, string role, int?schoolId)
        {
            try
            {
                using (SmacEntities context = new SmacEntities())
                {
                    if (op.Equals("ADD"))
                    {
                        if (GetUser(Id) != null)
                        {
                            throw new Exception("User was not created.  User ID already exists.");
                        }
                        else
                        {
                            var usr = new User
                            {
                                UserId         = Id,
                                FirstName      = fName,
                                MiddleName     = !string.IsNullOrWhiteSpace(mName) ? mName : null,
                                LastName       = lName,
                                EmailAddress   = !string.IsNullOrWhiteSpace(email) ? email : null,
                                PhoneNumber    = !string.IsNullOrWhiteSpace(phone) ? phone : null,
                                Gender         = (from a in context.Genders where a.GenderType == gender select a).FirstOrDefault(),
                                StartDate      = startDate.Value,
                                EndDate        = endDate,
                                IsActive       = isActive.Value,
                                UserCredential = new UserCredential()
                                {
                                    Password = UserCredentialEntity.GetSHA256Hash(password),
                                    UserName = userName
                                }
                            };

                            if (schoolId.HasValue)
                            {
                                usr.Schools.Add((from a in context.Schools where a.SchoolId == schoolId.Value select a).FirstOrDefault());
                            }

                            context.Users.Add(usr);
                            context.SaveChanges();

                            if (role == "admin")
                            {
                                Admin newRole = new Admin();
                                newRole.User = usr;
                                context.Admins.Add(newRole);
                                context.SaveChanges();
                            }
                            else if (role == "student")
                            {
                                Student newRole = new Student();
                                newRole.User = usr;
                                context.Students.Add(newRole);
                                context.SaveChanges();
                            }
                            else if (role == "staff")
                            {
                                Staff newRole = new Staff();
                                newRole.User = usr;
                                context.Staffs.Add(newRole);
                                context.SaveChanges();
                            }
                            else if (role == "teacher")
                            {
                                Teacher newRole = new Teacher();
                                newRole.User = usr;
                                context.Teachers.Add(newRole);
                                context.SaveChanges();
                            }
                        }
                    }
                    else if (op.Equals("EDIT"))
                    {
                        if ((from a in context.Users where a.UserId == Id select a).FirstOrDefault() == null)
                        {
                            throw new Exception("User was not updated.  User ID not found.");
                        }
                        else if (!string.IsNullOrWhiteSpace(newId) && newId != Id && (from a in context.Users where a.UserId == newId select a).FirstOrDefault() != null)
                        {
                            throw new Exception("User was not updated.  User ID already exists");
                        }
                        else
                        {
                            var user = (from a in context.Users where a.UserId == Id select a).FirstOrDefault();

                            user.UserId       = string.IsNullOrWhiteSpace(newId) ? Id : newId;
                            user.FirstName    = fName;
                            user.MiddleName   = !string.IsNullOrWhiteSpace(mName) ? mName : null;
                            user.LastName     = lName;
                            user.EmailAddress = !string.IsNullOrWhiteSpace(email) ? email : null;
                            user.PhoneNumber  = !string.IsNullOrWhiteSpace(phone) ? phone : null;
                            user.GenderType   = gender;
                            user.StartDate    = startDate.HasValue ? startDate.Value : user.StartDate;
                            user.EndDate      = endDate;
                            user.IsActive     = isActive.HasValue ? isActive.Value : user.IsActive;

                            context.Entry(user).State = System.Data.Entity.EntityState.Modified;
                            context.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }