Пример #1
0
 public EventLog(EventLog copyLog) : this()
 {
     DateReceived    = copyLog.DateReceived;
     Id              = copyLog.Id;
     LogType         = copyLog.LogType;
     Data            = copyLog.Data;
     Sender          = new OsbideUser(copyLog.Sender);
     SenderId        = copyLog.SenderId;
     AssemblyVersion = copyLog.AssemblyVersion;
 }
Пример #2
0
 public ActionRequestLog(ActionRequestLog other)
 {
     if (Creator != null)
     {
         Creator = new OsbideUser(other.Creator);
     }
     ActionName       = other.ActionName;
     ActionParameters = other.ActionParameters;
     ControllerName   = other.ControllerName;
     IpAddress        = other.IpAddress;
     AccessDate       = other.AccessDate;
 }
Пример #3
0
 public EventLog(IOsbideEvent evt, OsbideUser sender)
     : this(evt)
 {
     //were we sent a null user?
     if (sender.FirstName == null && sender.LastName == null)
     {
         //replace with a generic user
         sender = OsbideUser.GenericUser();
     }
     Sender = sender;
     if (sender.Id != 0)
     {
         SenderId = sender.Id;
     }
 }
Пример #4
0
 public OsbideUser(OsbideUser copyUser)
     : this()
 {
     Role                        = copyUser.Role;
     Id                          = copyUser.Id;
     FirstName                   = copyUser.FirstName;
     LastName                    = copyUser.LastName;
     InstitutionId               = copyUser.InstitutionId;
     Email                       = copyUser.Email;
     SchoolId                    = copyUser.SchoolId;
     LastVsActivity              = copyUser.LastVsActivity;
     ReceiveNotificationEmails   = copyUser.ReceiveNotificationEmails;
     ReceiveEmailOnNewAskForHelp = copyUser.ReceiveEmailOnNewAskForHelp;
     ReceiveEmailOnNewFeedPost   = copyUser.ReceiveEmailOnNewFeedPost;
     Gender                      = copyUser.Gender;
 }
Пример #5
0
 /// <summary>
 /// Encrypts the supplied password for the given user
 /// </summary>
 /// <param name="password"></param>
 /// <param name="user"></param>
 /// <returns></returns>
 public static string EncryptPassword(string password, OsbideUser user)
 {
     return(EncryptPassword(password, user.Email));
 }
Пример #6
0
        /// <summary>
        /// Inserts a user that has a preexisting ID into the database context.  Most likely to be used
        /// when inserting a user that already exists in another context.
        /// </summary>
        /// <param name="user">The user to insert</param>
        /// <returns>TRUE if everything went okay
        ///          FALSE if: User ID is 0
        ///                    User already exists
        ///                    Random query error
        /// </returns>
        public bool InsertUserWithId(OsbideUser user)
        {
            //ignore users with an empty ID
            if (user.Id == 0)
            {
                return(false);
            }

            //check to see if we already have a user with that ID
            OsbideUser dbUser = Users.Find(user.Id);

            if (dbUser != null)
            {
                return(false);
            }

            //finally, we can do a raw insert
            SqlCeConnection conn = new SqlCeConnection(this.Database.Connection.ConnectionString);

            try
            {
                conn.Open();
            }
            catch (Exception)
            {
                return(false);
            }

            string       query = "SET IDENTITY_INSERT OsbideUsers ON";
            SqlCeCommand cmd   = new SqlCeCommand(query, conn);

            try
            {
                object result = cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                return(false);
            }

            query = "INSERT INTO OsbideUsers " +
                    "(Id, FirstName, LastName, InstitutionId, OsbleId) " +
                    "VALUES (@id, @first, @last, @institutionId, @osbleId) ";
            cmd = new SqlCeCommand(query, conn);
            cmd.Parameters.Add(new SqlCeParameter()
            {
                ParameterName = "id",
                Value         = user.Id,
                SqlDbType     = System.Data.SqlDbType.Int
            });
            cmd.Parameters.Add(new SqlCeParameter()
            {
                ParameterName = "first",
                Value         = user.FirstName,
                SqlDbType     = System.Data.SqlDbType.NVarChar
            });

            cmd.Parameters.Add(new SqlCeParameter()
            {
                ParameterName = "last",
                Value         = user.LastName,
                SqlDbType     = System.Data.SqlDbType.NVarChar
            });

            cmd.Parameters.Add(new SqlCeParameter()
            {
                ParameterName = "institutionId",
                Value         = user.InstitutionId,
                SqlDbType     = System.Data.SqlDbType.NVarChar
            });

            try
            {
                cmd.ExecuteNonQuery();

                //turn off identity inserts
                query = "SET IDENTITY_INSERT OsbideUsers OFF";
                cmd   = new SqlCeCommand(query, conn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Пример #7
0
        public static void Seed(OsbideContext context)
        {
            //add in some sample schools
            School wsu = new School()
            {
                Name = "Washington State University"
            };

            context.Schools.Add(wsu);
            context.Schools.Add(new School()
            {
                Name = "Other Institution"
            });
            context.SaveChanges();

            //add in default chat rooms
            context.ChatRooms.Add(new ChatRoom()
            {
                Name = "General Chat", SchoolId = wsu.Id, IsDefaultRoom = true
            });
            context.ChatRooms.Add(new ChatRoom()
            {
                Name = "CptS 121 Chat", SchoolId = wsu.Id, IsDefaultRoom = false
            });
            context.ChatRooms.Add(new ChatRoom()
            {
                Name = "CptS 122 Chat", SchoolId = wsu.Id, IsDefaultRoom = false
            });
            context.ChatRooms.Add(new ChatRoom()
            {
                Name = "CptS 223 Chat", SchoolId = wsu.Id, IsDefaultRoom = false
            });

            //[obsolete]
            //add in some default subscriptions
            //context.UserSubscriptions.Add(new UserSubscription() { ObserverInstitutionId = 123, ObserverSchoolId = 1, SubjectSchoolId = 1, SubjectInstitutionId = 456 });
            //context.UserSubscriptions.Add(new UserSubscription() { ObserverInstitutionId = 123, ObserverSchoolId = 1, SubjectSchoolId = 1, SubjectInstitutionId = 789, IsRequiredSubscription = true });
            //context.UserSubscriptions.Add(new UserSubscription() { ObserverInstitutionId = 456, ObserverSchoolId = 1, SubjectSchoolId = 1, SubjectInstitutionId = 789, IsRequiredSubscription = true });

            //also set up some courses
            context.Courses.Add(new Course()
            {
                Name        = "OSBIDE 101",
                Year        = 2014,
                Season      = "Spring",
                SchoolId    = 1,
                Description = "Everything you ever wanted to know about OSBIDE."
            }
                                );

            context.Courses.Add(new Course()
            {
                Name        = "CptS 121",
                Year        = 2014,
                Season      = "Spring",
                SchoolId    = 1,
                Description = "Formulation of problems and top-down design of programs in a modern structured language for their solution on a digital computer."
            }
                                );

            context.Courses.Add(new Course()
            {
                Name        = "CptS 122",
                Year        = 2014,
                Season      = "Spring",
                SchoolId    = 1,
                Description = "This course is about advanced programming techniques, data structures, recursion, sorting, searching, and basic algorithm analysis."
            }
                                );

            context.Courses.Add(new Course()
            {
                Name        = "CptS 223",
                Year        = 2014,
                Season      = "Spring",
                SchoolId    = 1,
                Description = "Advanced data structures, object oriented programming concepts, concurrency, and program design principles."
            }
                                );

            context.Courses.Add(new Course()
            {
                Name        = "CptS 483",
                Year        = 2014,
                Season      = "Spring",
                SchoolId    = 1,
                Description = "Web development"
            }
                                );

            context.SaveChanges();

            //add some test users
            IdenticonRenderer renderer = new IdenticonRenderer();
            OsbideUser        joe      = new OsbideUser()
            {
                FirstName       = "Joe",
                LastName        = "User",
                Email           = "*****@*****.**",
                InstitutionId   = 123,
                SchoolId        = wsu.Id,
                Role            = SystemRole.Student,
                Gender          = Gender.Male,
                DefaultCourseId = 1
            };

            joe.SetProfileImage(renderer.Render(joe.Email.GetHashCode(), 128));
            context.Users.Add(joe);

            OsbideUser betty = new OsbideUser()
            {
                FirstName       = "Betty",
                LastName        = "Rogers",
                Email           = "*****@*****.**",
                InstitutionId   = 456,
                SchoolId        = wsu.Id,
                Role            = SystemRole.Student,
                Gender          = Gender.Female,
                DefaultCourseId = 1
            };

            betty.SetProfileImage(renderer.Render(betty.Email.GetHashCode(), 128));
            context.Users.Add(betty);
            context.SaveChanges();

            OsbideUser adam = new OsbideUser()
            {
                FirstName       = "Adam",
                LastName        = "Carter",
                Email           = "*****@*****.**",
                InstitutionId   = 789,
                SchoolId        = wsu.Id,
                Role            = SystemRole.Instructor,
                Gender          = Gender.Male,
                DefaultCourseId = 1
            };

            adam.SetProfileImage(renderer.Render(adam.Email.GetHashCode(), 128));
            context.Users.Add(adam);
            context.SaveChanges();

            //...and set their passwords
            UserPassword up = new UserPassword();

            up.UserId   = joe.Id;
            up.Password = UserPassword.EncryptPassword("123123", joe);
            context.UserPasswords.Add(up);

            up          = new UserPassword();
            up.UserId   = betty.Id;
            up.Password = UserPassword.EncryptPassword("123123", betty);
            context.UserPasswords.Add(up);

            up          = new UserPassword();
            up.UserId   = adam.Id;
            up.Password = UserPassword.EncryptPassword("123123", adam);
            context.UserPasswords.Add(up);
            context.SaveChanges();

            //add students to the courses
            context.Courses.Find(1).CourseUserRelationships.Add(new CourseUserRelationship()
            {
                UserId = 3, CourseId = 1, Role = CourseRole.Coordinator
            });
            context.Courses.Find(1).CourseUserRelationships.Add(new CourseUserRelationship()
            {
                UserId = 1, CourseId = 1, Role = CourseRole.Student
            });
            context.Courses.Find(1).CourseUserRelationships.Add(new CourseUserRelationship()
            {
                UserId = 2, CourseId = 1, Role = CourseRole.Assistant
            });

            context.Courses.Find(2).CourseUserRelationships.Add(new CourseUserRelationship()
            {
                UserId = 3, CourseId = 2, Role = CourseRole.Coordinator
            });
            context.Courses.Find(2).CourseUserRelationships.Add(new CourseUserRelationship()
            {
                UserId = 1, CourseId = 2, Role = CourseRole.Student
            });
            context.Courses.Find(2).CourseUserRelationships.Add(new CourseUserRelationship()
            {
                UserId = 2, CourseId = 2, Role = CourseRole.Assistant
            });
            context.SaveChanges();
        }
Пример #8
0
 public ActionRequestLog()
 {
     AccessDate = DateTime.UtcNow;
     Creator    = new OsbideUser();
 }