Example #1
0
 public FeedController()
 {
     _userSettings = (from setting in Db.UserFeedSettings
                      where setting.UserId == CurrentUser.Id
                      orderby setting.Id descending
                      select setting)
                     .Take(1)
                     .FirstOrDefault();
 }
Example #2
0
        /// <summary>
        /// Constructs a basic query to be further manipulated by other functions in this class
        /// </summary>
        /// <returns></returns>
        private ActivityFeedQuery BuildBasicQuery(ActivityFeedQuery query = null)
        {
            //check for null query
            if (query == null)
            {
                query = new ActivityFeedQuery();
            }

            //add the event types that the user wants to see
            UserFeedSetting feedSettings = _userSettings;

            if (feedSettings == null || feedSettings.ActiveSettings.Count == 0)
            {
                foreach (var evt in ActivityFeedQuery.GetAllEvents())
                {
                    query.AddEventType(evt);
                }
            }
            else
            {
                //load in event filter settings
                foreach (EventFilterSetting setting in feedSettings.ActiveSettings)
                {
                    query.AddEventType(UserFeedSetting.FeedOptionToOsbideEvent(setting));
                }

                //load in course and user type filtering
                query.CourseRoleFilter = (CourseRole)feedSettings.CourseRoleFilter;
                query.CourseFilter     = new Course()
                {
                    Id = feedSettings.CourseFilter
                };
            }

            return(query);
        }
Example #3
0
        public ActionResult ApplyFeedFilter(FormCollection formCollection)
        {
            try
            {
                // update user settings in database
                UserFeedSetting feedSetting = _userSettings;
                if (feedSetting == null)
                {
                    feedSetting        = new UserFeedSetting();
                    feedSetting.UserId = CurrentUser.Id;
                }
                else
                {
                    feedSetting              = new UserFeedSetting(feedSetting);
                    feedSetting.Id           = 0;
                    feedSetting.SettingsDate = DateTime.UtcNow;
                }
                Db.UserFeedSettings.Add(feedSetting);

                //clear out existing settings
                feedSetting.EventFilterSettings = 0;

                //load in new settings
                foreach (string key in Request.Form.Keys)
                {
                    if (key.StartsWith("event_") == true)
                    {
                        string[] pieces = key.Split('_');
                        if (pieces.Length == 2)
                        {
                            EventTypes evt;
                            if (Enum.TryParse <EventTypes>(pieces[1], true, out evt))
                            {
                                feedSetting.SetSetting(evt, true);
                            }
                        }
                    }
                }

                //check for course filter
                if (Request.Form.AllKeys.Contains("course-filter"))
                {
                    int courseId = -1;
                    Int32.TryParse(Request.Form["course-filter"], out courseId);
                    feedSetting.CourseFilter = courseId;
                }

                //check for user filter
                if (Request.Form.AllKeys.Contains("user-type-filter"))
                {
                    int userRoleId = (int)CourseRole.Student;
                    Int32.TryParse(Request.Form["user-type-filter"], out userRoleId);
                    feedSetting.CourseRoleFilter = userRoleId;
                }

                //save changes
                Db.SaveChanges();

                //apply filter reload page
                var errorType = Request.Form.AllKeys.Contains("error-type") ? Request.Form["error-type"] : string.Empty;
                var keyword   = ((EventFilterSetting)feedSetting.EventFilterSettings & EventFilterSetting.FeedPostEvent) == EventFilterSetting.FeedPostEvent &&
                                Request.Form.AllKeys.Contains("keyword") ? Request.Form["keyword"] : string.Empty;

                return(RedirectToAction("Index", new { errorType = errorType, keyword = keyword }));
            }
            catch (Exception ex)
            {
                LogErrorMessage(ex);
                return(RedirectToAction("FeedDown", "Error"));
            }
        }
Example #4
0
        public ActionResult Create(CreateAccountViewModel vm)
        {
            if (ModelState.IsValid)
            {
                bool userExists           = false;
                bool identificationExists = false;
                ViewBag.UserExistsError     = false;
                ViewBag.SchoolIdExistsError = false;

                //make sure that the email address is unique
                OsbideUser user = Db.Users.Where(u => u.Email.CompareTo(vm.Email) == 0).FirstOrDefault();
                if (user != null)
                {
                    ModelState.AddModelError("", "A user with that email already exists.");
                    userExists = true;
                    ViewBag.UserExistsError = true;
                }

                //make sure that the institution id has not been used for the selected school
                user = (from u in Db.Users
                        where u.SchoolId.CompareTo(vm.User.SchoolId) == 0 &&
                        u.InstitutionId.CompareTo(vm.User.InstitutionId) == 0
                        select u
                        ).FirstOrDefault();
                if (user != null)
                {
                    ModelState.AddModelError("", "There already exists a user at the selected institution with that ID number.");
                    identificationExists        = true;
                    ViewBag.SchoolIdExistsError = true;
                }

                //only continue if we were provided with a unique email and school id
                if (userExists == false && identificationExists == false)
                {
                    vm.User.Email           = vm.Email;
                    vm.User.Id              = 0;
                    vm.User.DefaultCourseId = 1;

                    Db.Users.Add(vm.User);
                    Db.SaveChanges();

                    //add password information
                    UserPassword password = new UserPassword();
                    password.UserId   = vm.User.Id;
                    password.Password = UserPassword.EncryptPassword(vm.Password, vm.User);
                    Db.UserPasswords.Add(password);
                    Db.SaveChanges();

                    //add default feed options
                    UserFeedSetting feedSetting = new UserFeedSetting();
                    feedSetting.UserId = vm.User.Id;
                    foreach (var evt in ActivityFeedQuery.GetSocialEvents())
                    {
                        feedSetting.SetSetting(evt, true);
                    }
                    Db.UserFeedSettings.Add(feedSetting);
                    Db.SaveChanges();

                    //enroll them in OSBIDE 101
                    Db.CourseUserRelationships.Add(new CourseUserRelationship()
                    {
                        UserId = vm.User.Id, CourseId = 1, Role = CourseRole.Student
                    });
                    vm.User.DefaultCourseId = 1;
                    Db.SaveChanges();

                    //log user in
                    Authentication auth = new Authentication();
                    auth.LogIn(vm.User);

                    //redirect to profile page
                    return(RedirectToAction("Index", "Feed"));
                }
            }

            //shouldn't get here unless we received an error
            //call base Create logic
            Create();
            return(View());
        }