Exemplo n.º 1
0
        public ActionResult Index()
        {
            ViewBag.Title = "Announcements";
            ViewBag.Message = "The information you need to game with you buddies.";

            IndexModel newIndexModel = new IndexModel();
            using (CGWebEntities cgweb = new CGWebEntities())
            {
                List<Announcement> announcements;

                if (Request.IsAuthenticated)
                {

                    UserProfile currentProfile = cgweb.UserProfiles.Where(UP => UP.UserName.Equals(User.Identity.Name)).Single();
                    List<int> roleIds = currentProfile.webpages_Roles.Select(WR => WR.RoleId).ToList();
                    announcements = cgweb.Announcements.Where(A => !A.RestrictToRole.HasValue || roleIds.Contains(A.RestrictToRole.Value)).ToList();
                }
                else
                {
                    announcements = cgweb.Announcements.Where(A => !A.RestrictToRole.HasValue).ToList();
                }
                newIndexModel.Announcements = new List<Models.Shared.AnnouncementPartialModel>();
                foreach (Announcement announce in announcements)
                    newIndexModel.Announcements.Add(announce.BuildAnnouncementPartialModel());
            }

            return View(newIndexModel);
        }
Exemplo n.º 2
0
 public void PerformGenerationJob(CGDataEntities.CGWebEntities webEntities)
 {
     log.Info("Starting ServiceGenerationJob...");
     AddServices(webEntities);
     AddServiceRoleRelationships(webEntities);
     log.Info("ServiceGenerationJob Complete...");
 }
Exemplo n.º 3
0
        private void AsignUserRoles(CGDataEntities.CGWebEntities webEntities)
        {
            SimpleRoleProvider provider = new SimpleRoleProvider();

            List <int> roleKeyList = _usersInRoles.Select(T => T.Value).Distinct().ToList();

            foreach (int roleKey in roleKeyList)
            {
                string   roleName           = _roles[roleKey];
                int[]    usersInRoleIndexes = _usersInRoles.Where(kv => kv.Value.Equals(roleKey)).Select(kv => kv.Key).ToArray();
                string[] userNames          = new string[usersInRoleIndexes.Count()];

                for (int i = 0; i < usersInRoleIndexes.Count(); i++)
                {
                    userNames[i] = _userProfileList[usersInRoleIndexes[i]].Username;
                }

                //wont work without HttpContext :(
                //provider.AddUsersToRoles(userNames, roleNames);
                webpages_Roles currentRole = webEntities.webpages_Roles.Where(R => R.RoleName.Equals(roleName)).Single();
                foreach (UserProfile profile in webEntities.UserProfiles.Where(UP => userNames.Contains(UP.UserName)))
                {
                    profile.webpages_Roles.Add(currentRole);
                }
                webEntities.SaveChanges();
            }

            log.Info("Added Roles to system.");
        }
Exemplo n.º 4
0
        public ActionResult ManageUser(CincyGeeksWebsite.Models.Shared.UserProfile postedProfile)
        {
            using (CGWebEntities entities = new CGWebEntities())
            {

                UserProfile profile = entities.UserProfiles.Where(up => up.UserId.Equals(postedProfile.UserId)).Single();
                profile.AvatarFileName = postedProfile.AvatarFileName;
                profile.BanExpireDate = postedProfile.BanExpireDate;
                profile.Email = postedProfile.Email;
                profile.ListInDirectory = postedProfile.ListInDirectory;
                profile.PhoneNumber = postedProfile.PhoneNumber;
                profile.Signature = postedProfile.Signature;
                profile.SteamHandle = postedProfile.SteamHandle;
                profile.Timezone = postedProfile.Timezone;
                profile.UserName = postedProfile.UserName;

                try
                {
                    entities.SaveChanges();
                    ViewBag.SaveMessage = "Updated Okay.";
                }
                catch (Exception ex)
                {
                    ViewBag.SaveMessage = String.Format("There was a problem : {0}", ex.Message);
                }

                return View(postedProfile);
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            log.Info("Checking developer lacking caffinee...");
            Console.WriteLine("This will clear and factory reset the database.");
            Console.WriteLine("!!!Any change you have made manually will disapear!!!");
            Console.WriteLine("You sure? (y to DELETE ALL THE THINGS!)");

            if (Console.ReadKey().Key == ConsoleKey.Y)
            {
                log.Info("Caffinee levels confirmed. Starting CgWebDataGenerator...");

                Stopwatch generationTimer = new Stopwatch();
                generationTimer.Start();

                log.Info("Calling WebSecurity.InitializeDatabaseConnection()...");
                WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: false);

                log.Info("Opening database context.");
                using (CGWebEntities entities = new CGWebEntities())
                {
                    log.Info("Stepping generation actions...");
                    for (int i = 0; i < _generationActions.Count(); i++)
                    {
                        log.Info(String.Format("Trying initalization for type {0}", _generationActions[i].GetType()));
                        try
                        {
                            _generationActions[i].InitalizeGenerationJob();
                        }
                        catch (Exception ex)
                        {
                            log.Error(String.Format("There was a problem initalizing type {0}", _generationActions[i].GetType()), ex);
                            HangForUserAndExit(1);
                        }

                        log.Info(String.Format("Trying generationAction for type {0}", _generationActions[i].GetType()));
                        try
                        {
                            _generationActions[i].PerformGenerationJob(entities);
                        }
                        catch (Exception ex)
                        {
                            log.Error(String.Format("There was a problem in generationAction for type {0}", _generationActions[i].GetType()), ex);
                            HangForUserAndExit(1);
                        }
                    }
                    log.Info("All generation modules performed without error.");
                }
                log.Info("Disposed of database context");
                generationTimer.Stop();

                log.Info(String.Format("CgWebDataGenerator has ended. Generation took: {0}", generationTimer.Elapsed.ToString()));

                HangForUserAndExit(0);
            }
            else
            {
                Console.WriteLine("I'll get you next time Gadget...");
                Environment.Exit(0);
            }
        }
Exemplo n.º 6
0
 public void PerformGenerationJob(CGDataEntities.CGWebEntities webEntities)
 {
     log.Info("Starting UserSchemaGenerationJob...");
     CreateNewRoles(webEntities);
     CreateNewUsers();
     AsignUserRoles(webEntities);
     log.Info("UserSchemaGenerationJob Complete!");
 }
Exemplo n.º 7
0
        public ActionResult ManageUser(int userId)
        {
            using(CGWebEntities entities = new CGWebEntities())
            {

                UserProfile profile = entities.UserProfiles.Where(up => up.UserId.Equals(userId)).Single();

                return View(new CincyGeeksWebsite.Models.Shared.UserProfile(profile));
            }
        }
Exemplo n.º 8
0
 private void AddServices(CGDataEntities.CGWebEntities webEntities)
 {
     foreach (KeyValuePair <string, Guid> service in _servicesDict)
     {
         webEntities.Services.Add(new CGDataEntities.Service()
         {
             ServiceId   = service.Value,
             ServiceName = service.Key
         });
     }
     webEntities.SaveChanges();
     log.Info("Added services to system.");
 }
Exemplo n.º 9
0
        private void CreateNewRoles(CGDataEntities.CGWebEntities webEntities)
        {
            //wont work without HttpContext :(
            //SimpleRoleProvider provider = new SimpleRoleProvider();
            //foreach (KeyValuePair<int, string> roleKV in _roles)
            //    provider.CreateRole(roleKV.Value);

            foreach (KeyValuePair <int, string> roleKV in _roles)
            {
                webEntities.webpages_Roles.Add(new webpages_Roles()
                {
                    RoleName = roleKV.Value
                });
            }
            webEntities.SaveChanges();
            log.Info("Added roles to system.");
        }
Exemplo n.º 10
0
        public ActionResult DeleteUser(int userId)
        {
            using (CGWebEntities entities = new CGWebEntities())
            {
                UserProfile profile = entities.UserProfiles.Where(up => up.UserId.Equals(userId)).Single();
                List<webpages_Roles> roleDropList = profile.webpages_Roles.ToList();

                foreach (webpages_Roles role in roleDropList)
                    entities.webpages_Roles.Remove(role);
                entities.SaveChanges();

                entities.UserProfiles.Remove(profile);
                entities.SaveChanges();
            }

            return Redirect("~/Administration/UserDashboard");
        }
Exemplo n.º 11
0
 private void AddServiceRoleRelationships(CGDataEntities.CGWebEntities webEntities)
 {
     foreach (KeyValuePair <string, Guid> service in _servicesDict)
     {
         Service currentService = webEntities.Services.Where(S => S.ServiceId.Equals(service.Value)).Single();
         foreach (KeyValuePair <string, string> relationship in _serviceRoleRelationships)
         {
             webpages_Roles currentRole = webEntities.webpages_Roles.Where(R => R.RoleName.Equals(relationship.Value)).Single();
             currentService.Service_Roles.Add(new Service_Roles()
             {
                 RoleId        = currentRole.RoleId,
                 ServiceId     = currentService.ServiceId,
                 ServiceRoleId = Guid.NewGuid()
             });
         }
     }
     webEntities.SaveChanges();
     log.Info("Added services role relationships to system.");
 }
Exemplo n.º 12
0
 public PartialViewResult Avatar(AvatarRenderModel renderModel)
 {
     AvatarPartialViewModel model;
     using (CGWebEntities entities = new CGWebEntities())
     {
         CGDataEntities.UserProfile currentProfile = entities.UserProfiles.Include("webpages_Roles").Where(UPE => UPE.UserId.Equals(renderModel.UserId)).Single();
         string fileName = String.IsNullOrEmpty(currentProfile.AvatarFileName) ? "DefaultAvatar.png" : currentProfile.AvatarFileName;
         model = new AvatarPartialViewModel()
         {
             AltText = "[CG] |" + currentProfile.UserName + "|",
             Height = 64,
             Width = 64,
             ResourcePath = "~/Content/avatars/" + fileName,
             StatsInfo = currentProfile.BanExpireDate.HasValue ? "Banned" : "Active",
             UserName = currentProfile.UserName,
             UserType = currentProfile.webpages_Roles.Where(R => R.RoleId == currentProfile.webpages_Roles.Min(R2 => R2.RoleId)).Single().RoleName,
             ImageOnly = renderModel.PictureOnly
         };
         return PartialView("_AvatarPartial", model);
     }
 }
Exemplo n.º 13
0
        public ActionResult ViewForum(Guid forumId, string topicTitle, string topicDescription, bool isPublic)
        {
            using (CGWebEntities entities = new CGWebEntities())
            {
                UserProfile currentUserProfile = entities.UserProfiles.Where(P => P.UserName.Equals(User.Identity.Name)).Single();

                ForumTopic newTopic = new ForumTopic()
                {
                    CreatedBy = currentUserProfile.UserId,
                    CreatedOn = DateTime.UtcNow,
                    ForumId = forumId,
                    IsPublic = isPublic,
                    TopicDescription = topicDescription,
                    TopicId = Guid.NewGuid(),
                    TopicTitle = HtmlSanitizerUtility.SanitizeInputStringNoHTML(topicTitle)
                };
                entities.ForumTopics.Add(newTopic);
                entities.SaveChanges();
            }

            return ViewForum(forumId);
        }
Exemplo n.º 14
0
        //
        // GET: /Forum/
        public ActionResult Index()
        {
            ForumIndexModel indexModel = new ForumIndexModel()
            {
                Forums = new Dictionary<string, Guid>()
            };

            using (CGWebEntities entities = new CGWebEntities())
            {
                if (Request.IsAuthenticated)
                {
                    foreach (Forum forum in entities.Forums)
                        indexModel.Forums.Add(forum.ForumTitle, forum.ForumId);
                }
                else
                {
                    foreach (Forum forum in entities.Forums.Where(F => F.IsPublic))
                        indexModel.Forums.Add(forum.ForumTitle, forum.ForumId);
                }
            }
            return View(indexModel);
        }
Exemplo n.º 15
0
        public ActionResult ViewForum(Guid forumId)
        {
            ViewForumModel viewForumModel = new ViewForumModel(){};

            using (CGWebEntities entities = new CGWebEntities())
            {
                Forum currentForum = entities.Forums.Where(F => F.ForumId.Equals(forumId)).Single();

                if (!currentForum.IsPublic && !Request.IsAuthenticated)
                    return RedirectToAction("Login", "Account");

                if (Request.IsAuthenticated)
                {
                    viewForumModel = currentForum.ConvertToViewForumModel(true, false);
                }
                else
                {
                    viewForumModel = currentForum.ConvertToViewForumModel(true, true);
                }
            }

            return View(viewForumModel);
        }
Exemplo n.º 16
0
        public void PerformGenerationJob(CGDataEntities.CGWebEntities webEntities)
        {
            log.Info("Starting AnnouncementGenerationJob...");
            using (CGWebEntities entities = new CGWebEntities())
            {
                foreach (AnnouncementStruct announce in _announcements)
                {
                    entities.Announcements.Add(new Announcement()
                    {
                        Content        = announce.Content,
                        CreatedBy      = announce.CreatedByUser,
                        CreatedDate    = announce.CreateDate,
                        IsPublic       = announce.IsPublic,
                        ModifiedBy     = announce.ModifiedByUser,
                        ModifiedDate   = announce.ModifiedDate,
                        RestrictToRole = announce.RestrictToRole,
                        Title          = announce.Title
                    });
                }

                entities.SaveChanges();
            }
            log.Info("AnnouncementGenerationJob Complete...");
        }
Exemplo n.º 17
0
        public ActionResult ViewTopic(ForumTopicRequestModel requestModel)
        {
            ViewTopicModel viewTopicModel = new ViewTopicModel(){
                Threads = new List<ForumThreadModel>()
            };

            using (CGWebEntities entities = new CGWebEntities())
            {
                ForumTopic currentTopic = entities.ForumTopics.Where(T => T.TopicId.Equals(requestModel.TopicId)).Single();
                viewTopicModel.CurrentTopic = currentTopic.ConvertToForumTopicModel();
                viewTopicModel.ParentForum = currentTopic.Forum.ConvertToViewForumModel(false, false);

                if(!currentTopic.IsPublic && !Request.IsAuthenticated)
                    return RedirectToAction("Login", "Account");

                var currentTopicGroup = entities.ForumThreads.Where(FT => FT.ForumTopic.Equals(requestModel.TopicId));

                int currentTopicViewLimit = Convert.ToInt32(ConfigurationManager.AppSettings["ForumTopicPagingLimit"]);
                viewTopicModel.CurrentPage = requestModel.CurrentPage;
                viewTopicModel.MaxPages = (int)Math.Ceiling((double)currentTopicGroup.Count() / (double)currentTopicViewLimit);

                foreach (ForumThread thread in currentTopicGroup.OrderByDescending(FT => FT.CreatedOn).OrderByDescending(FT => FT.IsSticky).Skip(currentTopicViewLimit * requestModel.CurrentPage).Take(currentTopicViewLimit))
                {
                    viewTopicModel.Threads.Add(thread.ConvertToForumThreadModel(false));
                }
            }

            return View(viewTopicModel);
        }
Exemplo n.º 18
0
        public ActionResult ManageUserRoles(RoleManagementModel model)
        {
            using (CGWebEntities entities = new CGWebEntities())
            {
                UserProfile selectedProfile = entities.UserProfiles.Where(up => up.UserId.Equals(model.UserId)).Single();

                if (model.Root)
                {
                    if (!selectedProfile.webpages_Roles.Any(r => r.RoleName.Equals("Root")))
                    {
                        selectedProfile.webpages_Roles.Add(entities.webpages_Roles.Where(r => r.RoleName.Equals("Root")).Single());
                    }
                }
                else
                {
                    webpages_Roles roleTest = selectedProfile.webpages_Roles.Where(r => r.RoleName.Equals("Root")).SingleOrDefault();
                    if (roleTest != null)
                    {
                        selectedProfile.webpages_Roles.Remove(roleTest);
                    }
                }

                if (model.Administrator)
                {
                    if (!selectedProfile.webpages_Roles.Any(r => r.RoleName.Equals("Administrator")))
                    {
                        selectedProfile.webpages_Roles.Add(entities.webpages_Roles.Where(r => r.RoleName.Equals("Administrator")).Single());
                    }
                }
                else
                {
                    webpages_Roles roleTest = selectedProfile.webpages_Roles.Where(r => r.RoleName.Equals("Administrator")).SingleOrDefault();
                    if (roleTest != null)
                    {
                        selectedProfile.webpages_Roles.Remove(roleTest);
                    }
                }

                if (model.Moderator)
                {
                    if (!selectedProfile.webpages_Roles.Any(r => r.RoleName.Equals("Moderator")))
                    {
                        selectedProfile.webpages_Roles.Add(entities.webpages_Roles.Where(r => r.RoleName.Equals("Moderator")).Single());
                    }
                }
                else
                {
                    webpages_Roles roleTest = selectedProfile.webpages_Roles.Where(r => r.RoleName.Equals("Moderator")).SingleOrDefault();
                    if (roleTest != null)
                    {
                        selectedProfile.webpages_Roles.Remove(roleTest);
                    }
                }

                if (model.User)
                {
                    if (!selectedProfile.webpages_Roles.Any(r => r.RoleName.Equals("User")))
                    {
                        selectedProfile.webpages_Roles.Add(entities.webpages_Roles.Where(r => r.RoleName.Equals("User")).Single());
                    }
                }
                else
                {
                    webpages_Roles roleTest = selectedProfile.webpages_Roles.Where(r => r.RoleName.Equals("User")).SingleOrDefault();
                    if (roleTest != null)
                    {
                        selectedProfile.webpages_Roles.Remove(roleTest);
                    }
                }

                if (model.Announcer)
                {
                    if (!selectedProfile.webpages_Roles.Any(r => r.RoleName.Equals("Announcer")))
                    {
                        selectedProfile.webpages_Roles.Add(entities.webpages_Roles.Where(r => r.RoleName.Equals("Announcer")).Single());
                    }
                }
                else
                {
                    webpages_Roles roleTest = selectedProfile.webpages_Roles.Where(r => r.RoleName.Equals("Announcer")).SingleOrDefault();
                    if (roleTest != null)
                    {
                        selectedProfile.webpages_Roles.Remove(roleTest);
                    }
                }

                try
                {
                    entities.SaveChanges();
                    ViewBag.SaveMessage = "Save Completed";
                }
                catch (Exception ex)
                {
                    ViewBag.SaveMessage = String.Format("There was a problem saving : {0}", ex.Message);
                }

                return View("ManageUserRoles", model);
            }
        }
Exemplo n.º 19
0
        public ActionResult ViewThread(ForumThreadRequestModel requestModel)
        {
            ViewThreadModel viewThreadModel = new ViewThreadModel(){
                Replies = new List<ForumReplyModel>()
            };

            using (CGWebEntities entities = new CGWebEntities())
            {
                ForumThread currentThread = entities.ForumThreads.Where(FT => FT.ThreadId.Equals(requestModel.ThreadId)).Single();

                viewThreadModel.ParentTopic = currentThread.ParentForumTopic.ConvertToForumTopicModel();

                if(!currentThread.ParentForumTopic.IsPublic && !Request.IsAuthenticated)
                    return RedirectToAction("Login", "Account");

                int currentPagingLimit = Convert.ToInt32(ConfigurationManager.AppSettings["ForumReplyPagingLimit"]);
                viewThreadModel.CurrentPage = requestModel.CurrentPage;
                viewThreadModel.MaxPages = (int)Math.Ceiling((double)currentThread.ForumReplies.Count / (double)currentPagingLimit);

                viewThreadModel.CurrentThread = currentThread.ConvertToForumThreadModel(true);

                foreach (ForumReply reply in currentThread.ForumReplies.OrderBy(FR => FR.CreatedOn).Skip(requestModel.CurrentPage * currentPagingLimit).Take(currentPagingLimit))
                {
                    viewThreadModel.Replies.Add(reply.ConvertToThreadReplyModel(true));
                }
            }

            return View(viewThreadModel);
        }
Exemplo n.º 20
0
        public void PerformGenerationJob(CGDataEntities.CGWebEntities webEntities)
        {
            log.Info("Starting AnnouncementGenerationJob...");
            using (CGWebEntities entities = new CGWebEntities())
            {
                foreach (AnnouncementStruct announce in _announcements)
                {
                    entities.Announcements.Add(new Announcement()
                    {
                        Content = announce.Content,
                        CreatedBy = announce.CreatedByUser,
                        CreatedDate = announce.CreateDate,
                        IsPublic = announce.IsPublic,
                        ModifiedBy = announce.ModifiedByUser,
                        ModifiedDate = announce.ModifiedDate,
                        RestrictToRole = announce.RestrictToRole,
                        Title = announce.Title
                    });
                }

                entities.SaveChanges();
            }
            log.Info("AnnouncementGenerationJob Complete...");
        }
Exemplo n.º 21
0
 public ActionResult UserDashboard()
 {
     List<CGDataEntities.UserProfile> viewRecords;
     using (CGWebEntities entities = new CGWebEntities())
     {
         viewRecords = entities.UserProfiles.ToList();
     }
     return View(viewRecords);
 }
        public void PerformGenerationJob(CGDataEntities.CGWebEntities webEntities)
        {
            log.Info("Starting data purge...");

            List <ForumReply> replysToRemove = webEntities.ForumReplies.ToList();

            webEntities.ForumReplies.RemoveRange(replysToRemove);
            webEntities.SaveChanges();

            List <ForumThread> threadsToRemove = webEntities.ForumThreads.ToList();

            webEntities.ForumThreads.RemoveRange(threadsToRemove);
            webEntities.SaveChanges();

            List <ForumTopic> topicsToRemove = webEntities.ForumTopics.ToList();

            webEntities.ForumTopics.RemoveRange(topicsToRemove);
            webEntities.SaveChanges();

            List <Forum> forumsToRemove = webEntities.Forums.ToList();

            webEntities.Forums.RemoveRange(forumsToRemove);
            webEntities.SaveChanges();

            List <Announcement> announcementsToRemove = webEntities.Announcements.ToList();

            webEntities.Announcements.RemoveRange(announcementsToRemove);
            webEntities.SaveChanges();

            foreach (UserProfile profile in webEntities.UserProfiles)
            {
                List <webpages_Roles> roles = profile.webpages_Roles.ToList();
                foreach (webpages_Roles role in roles)
                {
                    profile.webpages_Roles.Remove(role);
                }
            }
            webEntities.SaveChanges();

            List <Service_Roles> serviceRoleToRemove = webEntities.Service_Roles.ToList();

            webEntities.Service_Roles.RemoveRange(serviceRoleToRemove);

            webEntities.SaveChanges();

            List <UserProfile> profilesToRemove = webEntities.UserProfiles.ToList();

            webEntities.UserProfiles.RemoveRange(profilesToRemove);

            List <webpages_OAuthMembership> oAuthToRemove = webEntities.webpages_OAuthMembership.ToList();

            webEntities.webpages_OAuthMembership.RemoveRange(oAuthToRemove);

            List <webpages_Membership> membershipToRemove = webEntities.webpages_Membership.ToList();

            webEntities.webpages_Membership.RemoveRange(membershipToRemove);

            List <webpages_Roles> rolesToRemove = webEntities.webpages_Roles.ToList();

            webEntities.webpages_Roles.RemoveRange(rolesToRemove);

            List <Service> servicesToRemove = webEntities.Services.ToList();

            webEntities.Services.RemoveRange(servicesToRemove);

            webEntities.SaveChanges();

            log.Info("Current user data purged! Hope you didn't need that :O");
        }
Exemplo n.º 23
0
        public void PerformGenerationJob(CGDataEntities.CGWebEntities webEntities)
        {
            log.Info("Starting FourmGenerationJob...");
            using (CGWebEntities entities = new CGWebEntities())
            {
                foreach (ForumStruct forum in _forums)
                {
                    entities.Forums.Add(new Forum()
                    {
                        ForumId    = forum.ForumId,
                        ForumTitle = forum.ForumTitle,
                        IsPublic   = forum.IsPublic
                    });
                }
                entities.SaveChanges();
                log.Info("Wrote Forums data.");

                foreach (ForumTopicStruct topic in _forumTopics)
                {
                    entities.ForumTopics.Add(new ForumTopic()
                    {
                        CreatedBy        = topic.CreatedBy,
                        CreatedOn        = topic.CreatedOn,
                        TopicDescription = topic.Description,
                        ForumId          = topic.ForumId,
                        IsPublic         = topic.IsPublic,
                        TopicTitle       = topic.Title,
                        TopicId          = topic.TopicId
                    });
                }
                entities.SaveChanges();
                log.Info("Wrote Forums Topic data.");

                foreach (ForumThreadStruct thread in _forumThreads)
                {
                    entities.ForumThreads.Add(new ForumThread()
                    {
                        CreatedBy     = thread.CreatedBy,
                        CreatedOn     = thread.CreatedOn,
                        IsSticky      = thread.IsSticky,
                        ModifiedOn    = thread.ModifiedOn,
                        ThreadContent = thread.ThreadContent,
                        ThreadId      = thread.ThreadId,
                        ThreadTitle   = thread.ThreadTitle,
                        ForumTopic    = thread.TopicId
                    });
                }
                entities.SaveChanges();
                log.Info("Wrote Forums Theads data.");

                foreach (ForumReplyStruct reply in _forumReplys)
                {
                    entities.ForumReplies.Add(new ForumReply()
                    {
                        ReplyContent   = reply.Content,
                        CreatedBy      = reply.CreatedBy,
                        CreatedOn      = reply.CreatedOn,
                        ModifiedOn     = reply.ModifiedOn,
                        ParentThreadId = reply.ParentThreadId,
                        ReplyId        = reply.ReplyId
                    });
                }
                entities.SaveChanges();
                log.Info("Wrote Forums Reply data.");
            }
        }
Exemplo n.º 24
0
        public void InitalizeGenerationJob()
        {
            log.Info("Init AnnouncementGenerationJob");
            using (CGWebEntities entities = new CGWebEntities())
            {
                _currentUsers = entities.UserProfiles.ToList();
                _currentRoles = entities.webpages_Roles.ToList();

                _announcements = new List<AnnouncementStruct>()
                {
                    new AnnouncementStruct(){
                        Content = "This is the content of announcement #1",
                        CreateDate = DateTime.UtcNow,
                        CreatedByUser = _currentUsers.First().UserId,
                        IsPublic = true,
                        ModifiedByUser = null,
                        ModifiedDate = null,
                        RestrictToRole = null,
                        Title = "Announcement #1"
                    }
                };

                int iterator = 2;
                UserProfile createdBy = _currentUsers.Where(u => u.webpages_Roles.Any(r => r.RoleName.Equals("Announcer"))).First();

                foreach (webpages_Roles role in _currentRoles)
                {
                    _announcements.Add(new AnnouncementStruct()
                    {
                        Content = String.Format("This is the content of announcement #{0}", iterator),
                        CreateDate = DateTime.UtcNow,
                        CreatedByUser = createdBy.UserId,
                        IsPublic = false,
                        ModifiedByUser = null,
                        ModifiedDate = null,
                        RestrictToRole = role.RoleId,
                        Title = role.RoleName + " Announcement."
                    });

                    iterator++;
                }

                _announcements.Add(new AnnouncementStruct()
                {
                    Content = "A modified announcement content!",
                    CreateDate = DateTime.UtcNow.AddMinutes(-5),
                    CreatedByUser = createdBy.UserId,
                    IsPublic = true,
                    ModifiedByUser = createdBy.UserId,
                    ModifiedDate = DateTime.UtcNow,
                    RestrictToRole = null,
                    Title = "A modified announcement."
                });
            }

            log.Info("Created Announcement List:");
            foreach (AnnouncementStruct announce in _announcements)
            {
                log.Info(
                    String.Format("{0},{1},{2},{3},{4},{5},{6},{7}",
                    announce.Title,
                    announce.Content,
                    announce.CreateDate,
                    announce.CreatedByUser,
                    announce.ModifiedDate,
                    announce.ModifiedByUser,
                    announce.IsPublic,
                    announce.RestrictToRole)
                    );
            }
        }
Exemplo n.º 25
0
        public void PerformGenerationJob(CGDataEntities.CGWebEntities webEntities)
        {
            log.Info("Starting FourmGenerationJob...");
            using (CGWebEntities entities = new CGWebEntities())
            {
                foreach (ForumStruct forum in _forums)
                {
                    entities.Forums.Add(new Forum()
                    {
                        ForumId = forum.ForumId,
                        ForumTitle = forum.ForumTitle,
                        IsPublic = forum.IsPublic
                    });
                }
                entities.SaveChanges();
                log.Info("Wrote Forums data.");

                foreach (ForumTopicStruct topic in _forumTopics)
                {
                    entities.ForumTopics.Add(new ForumTopic()
                    {
                        CreatedBy = topic.CreatedBy,
                        CreatedOn = topic.CreatedOn,
                        TopicDescription = topic.Description,
                        ForumId = topic.ForumId,
                        IsPublic = topic.IsPublic,
                        TopicTitle = topic.Title,
                        TopicId = topic.TopicId
                    });
                }
                entities.SaveChanges();
                log.Info("Wrote Forums Topic data.");

                foreach (ForumThreadStruct thread in _forumThreads)
                {
                    entities.ForumThreads.Add(new ForumThread()
                    {
                        CreatedBy = thread.CreatedBy,
                        CreatedOn = thread.CreatedOn,
                        IsSticky = thread.IsSticky,
                        ModifiedOn = thread.ModifiedOn,
                        ThreadContent = thread.ThreadContent,
                        ThreadId = thread.ThreadId,
                        ThreadTitle = thread.ThreadTitle,
                        ForumTopic = thread.TopicId
                    });
                }
                entities.SaveChanges();
                log.Info("Wrote Forums Theads data.");

                foreach (ForumReplyStruct reply in _forumReplys)
                {
                    entities.ForumReplies.Add(new ForumReply()
                    {
                        ReplyContent = reply.Content,
                        CreatedBy = reply.CreatedBy,
                        CreatedOn = reply.CreatedOn,
                        ModifiedOn = reply.ModifiedOn,
                        ParentThreadId = reply.ParentThreadId,
                        ReplyId = reply.ReplyId
                    });
                }
                entities.SaveChanges();
                log.Info("Wrote Forums Reply data.");
            }
        }
Exemplo n.º 26
0
        public ActionResult ViewTopic(Guid topicId, string threadTitle, string threadContent, bool isSticky)
        {
            ViewTopicModel viewTopicModel = new ViewTopicModel()
            {
                Threads = new List<ForumThreadModel>()
            };

            using (CGWebEntities entities = new CGWebEntities())
            {
                UserProfile currentUserProfile = entities.UserProfiles.Where(P => P.UserName.Equals(User.Identity.Name)).Single();

                ForumThread newThread = new ForumThread()
                {
                    CreatedBy = currentUserProfile.UserId,
                    CreatedOn = DateTime.UtcNow,
                    ForumTopic = topicId,
                    IsSticky = isSticky,
                    ModifiedOn = null,
                    ThreadContent = threadContent,
                    ThreadId = Guid.NewGuid(),
                    ThreadTitle = HtmlSanitizerUtility.SanitizeInputStringNoHTML(threadTitle)
                };

                entities.ForumThreads.Add(newThread);
                entities.SaveChanges();
                ModelState.Clear();

                ForumTopic currentTopic = entities.ForumTopics.Where(T => T.TopicId.Equals(topicId)).Single();
                viewTopicModel.CurrentTopic = currentTopic.ConvertToForumTopicModel();
                viewTopicModel.ParentForum = currentTopic.Forum.ConvertToViewForumModel(false, false);

                if (!currentTopic.IsPublic && !Request.IsAuthenticated)
                    return RedirectToAction("Login", "Account");

                var currentTopicGroup = entities.ForumThreads.Where(FT => FT.ForumTopic.Equals(topicId));

                int currentTopicViewLimit = Convert.ToInt32(ConfigurationManager.AppSettings["ForumTopicPagingLimit"]);
                viewTopicModel.MaxPages = (int)Math.Ceiling((double)currentTopicGroup.Count() / (double)currentTopicViewLimit);
                viewTopicModel.CurrentPage = viewTopicModel.MaxPages - 1;

                foreach (ForumThread thread in currentTopicGroup.OrderByDescending(FT => FT.CreatedOn).OrderByDescending(FT => FT.IsSticky).Skip(currentTopicViewLimit * viewTopicModel.CurrentPage).Take(currentTopicViewLimit))
                {
                    viewTopicModel.Threads.Add(thread.ConvertToForumThreadModel(false));
                }
            }

            return View(viewTopicModel);
        }
Exemplo n.º 27
0
        public void InitalizeGenerationJob()
        {
            log.Info("Init FourmGenerationJob");

            Random rand = new Random((int)DateTime.UtcNow.Ticks);

            using (CGWebEntities entities = new CGWebEntities())
            {
                _currentUsers = entities.UserProfiles.ToList();
            }

            _forums = new List<ForumStruct>{
                new ForumStruct()
                {
                    ForumId = Guid.NewGuid(),
                    ForumTitle = "Public Forum",
                    IsPublic = true
                },
                new ForumStruct()
                {
                    ForumId = Guid.NewGuid(),
                    ForumTitle = "Gaming",
                    IsPublic = false
                },
                new ForumStruct()
                {
                    ForumId = Guid.NewGuid(),
                    ForumTitle = "Meta",
                    IsPublic = false
                },
                new ForumStruct()
                {
                    ForumId = Guid.NewGuid(),
                    ForumTitle = "Website Support",
                    IsPublic = true
                }
            };
            log.Info("Created Forum List:");
            foreach (ForumStruct forum in _forums)
            {
                log.Info(
                    String.Format("{0},{1},{2}",
                    forum.ForumId,
                    forum.ForumTitle,
                    forum.IsPublic)
                    );
            }

            _forumTopics = new List<ForumTopicStruct>()
            {
                new ForumTopicStruct(){
                   CreatedBy =  _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                   CreatedOn = DateTime.UtcNow,
                   Description = "Discussion for EvE Online goes here.",
                   ForumId = _forums[1].ForumId,
                   IsPublic = false,
                   Title = "EvE Online",
                   TopicId = Guid.NewGuid()
                },
                new ForumTopicStruct(){
                   CreatedBy =  _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                   CreatedOn = DateTime.UtcNow,
                   Description = "Discussion for Counter Strike:Global Offensive goes here.",
                   ForumId = _forums[1].ForumId,
                   IsPublic = false,
                   Title = "Counter Strike:Global Offensive",
                   TopicId = Guid.NewGuid()
                },
                new ForumTopicStruct(){
                   CreatedBy =  _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                   CreatedOn = DateTime.UtcNow,
                   Description = "Discussion for the public goes here.",
                   ForumId = _forums[0].ForumId,
                   IsPublic = true,
                   Title = "Public Threads",
                   TopicId = Guid.NewGuid()
                },
                new ForumTopicStruct(){
                   CreatedBy =  _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                   CreatedOn = DateTime.UtcNow,
                   Description = "Discussion for the BOINC Team goes here.",
                   ForumId = _forums[2].ForumId,
                   IsPublic = false,
                   Title = "BOINC Team",
                   TopicId = Guid.NewGuid()
                },
                new ForumTopicStruct(){
                   CreatedBy =  _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                   CreatedOn = DateTime.UtcNow,
                   Description = "Report website bugs here.",
                   ForumId = _forums[3].ForumId,
                   IsPublic = true,
                   Title = "Bugs",
                   TopicId = Guid.NewGuid()
                }
            };
            log.Info("Created Forum Topic List:");
            foreach (ForumTopicStruct topic in _forumTopics)
            {
                log.Info(
                    String.Format("{0},{1},{2},{3},{4},{5},{6}",
                    topic.TopicId,
                    topic.ForumId,
                    topic.Title,
                    topic.Description,
                    topic.CreatedBy,
                    topic.CreatedOn,
                    topic.IsPublic)
                    );
            }

            _forumThreads = new List<ForumThreadStruct>()
            {
                new ForumThreadStruct(){
                    CreatedBy = _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                    CreatedOn = DateTime.UtcNow,
                    IsSticky = false,
                    ModifiedOn = null,
                    ThreadContent = "An Eve thread blah blah blah...",
                    ThreadId = Guid.NewGuid(),
                    ThreadTitle = "Eve Thread 01",
                    TopicId = _forumTopics[0].TopicId
                },
                new ForumThreadStruct(){
                    CreatedBy = _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                    CreatedOn = DateTime.UtcNow,
                    IsSticky = false,
                    ModifiedOn = null,
                    ThreadContent = "An Eve thread blah blah blah...",
                    ThreadId = Guid.NewGuid(),
                    ThreadTitle = "Eve Thread 02",
                    TopicId = _forumTopics[0].TopicId
                },
                new ForumThreadStruct(){
                    CreatedBy = _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                    CreatedOn = DateTime.UtcNow,
                    IsSticky = false,
                    ModifiedOn = null,
                    ThreadContent = "A Counter Strike:Global Offensive thread blah blah blah...",
                    ThreadId = Guid.NewGuid(),
                    ThreadTitle = "Counter Strike:Global Offensive 01",
                    TopicId = _forumTopics[1].TopicId
                },
                new ForumThreadStruct(){
                    CreatedBy = _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                    CreatedOn = DateTime.UtcNow,
                    IsSticky = false,
                    ModifiedOn = null,
                    ThreadContent = "A Counter Strike:Global Offensive thread blah blah blah...",
                    ThreadId = Guid.NewGuid(),
                    ThreadTitle = "Counter Strike:Global Offensive 02",
                    TopicId = _forumTopics[1].TopicId
                },
                new ForumThreadStruct(){
                    CreatedBy = _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                    CreatedOn = DateTime.UtcNow,
                    IsSticky = false,
                    ModifiedOn = null,
                    ThreadContent = "A public thread blah blah blah...",
                    ThreadId = Guid.NewGuid(),
                    ThreadTitle = "Public Thread",
                    TopicId = _forumTopics[2].TopicId
                },
                new ForumThreadStruct(){
                    CreatedBy = _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                    CreatedOn = DateTime.UtcNow,
                    IsSticky = false,
                    ModifiedOn = null,
                    ThreadContent = "A BOINC thread blah blah blah...",
                    ThreadId = Guid.NewGuid(),
                    ThreadTitle = "BOINC Thread",
                    TopicId = _forumTopics[3].TopicId
                },
                new ForumThreadStruct(){
                    CreatedBy = _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                    CreatedOn = DateTime.UtcNow,
                    IsSticky = true,
                    ModifiedOn = null,
                    ThreadContent = "A bug thread thread blah blah blah...",
                    ThreadId = Guid.NewGuid(),
                    ThreadTitle = "Bug Thread",
                    TopicId = _forumTopics[4].TopicId
                },
                new ForumThreadStruct(){
                    CreatedBy = _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                    CreatedOn = DateTime.UtcNow.AddSeconds(1),
                    IsSticky = true,
                    ModifiedOn = null,
                    ThreadContent = "A bug thread thread blah blah blah...",
                    ThreadId = Guid.NewGuid(),
                    ThreadTitle = "Bug Thread 02",
                    TopicId = _forumTopics[4].TopicId
                },
                new ForumThreadStruct(){
                    CreatedBy = _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                    CreatedOn = DateTime.UtcNow.AddSeconds(2),
                    IsSticky = true,
                    ModifiedOn = null,
                    ThreadContent = "A bug thread thread blah blah blah...",
                    ThreadId = Guid.NewGuid(),
                    ThreadTitle = "Bug Thread 03",
                    TopicId = _forumTopics[4].TopicId
                }
            };
            log.Info("Created Forum Thread List:");
            foreach (ForumThreadStruct thread in _forumThreads)
            {
                log.Info(
                    String.Format("{0},{1},{2},{3},{4},{5},{6},{7}",
                    thread.ThreadId,
                    thread.TopicId,
                    thread.ThreadTitle,
                    thread.ThreadContent,
                    thread.CreatedBy,
                    thread.ModifiedOn,
                    thread.CreatedOn,
                    thread.IsSticky)
                    );
            }

            _forumReplys = new List<ForumReplyStruct>()
            {
                new ForumReplyStruct(){
                    Content = "A reply, there is a bug dumbass",
                    CreatedBy = _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                    CreatedOn = DateTime.UtcNow,
                    ModifiedOn = null,
                    ParentThreadId = _forumThreads[6].ThreadId,
                    ReplyId = Guid.NewGuid()
                },
                new ForumReplyStruct(){
                    Content = "Found another one",
                    CreatedBy = _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                    CreatedOn = DateTime.UtcNow,
                    ModifiedOn = null,
                    ParentThreadId = _forumThreads[6].ThreadId,
                    ReplyId = Guid.NewGuid()
                }
            };

            for (int i = 0; i < 80; i++)
            {
                _forumReplys.Add(new ForumReplyStruct()
                {
                    Content = "A reply, there is a bug dumbass # " + i.ToString(),
                    CreatedBy = _currentUsers[rand.Next(0, _currentUsers.Count - 1)].UserId,
                    CreatedOn = DateTime.UtcNow.AddSeconds(i),
                    ModifiedOn = null,
                    ParentThreadId = _forumThreads[6].ThreadId,
                    ReplyId = Guid.NewGuid()
                });
            }

            log.Info("Created Forum Reply List:");
            foreach (ForumReplyStruct reply in _forumReplys)
            {
                log.Info(
                    String.Format("{0},{1},{2},{3},{4},{5}",
                    reply.ReplyId,
                    reply.ParentThreadId,
                    reply.Content,
                    reply.CreatedBy,
                    reply.CreatedOn,
                    reply.ModifiedOn)
                    );
            }
        }
Exemplo n.º 28
0
        public ActionResult ManageUserRoles(int userId)
        {
            using (CGWebEntities entities = new CGWebEntities())
            {
                UserProfile selectedProfile = entities.UserProfiles.Where(up => up.UserId.Equals(userId)).Single();

                RoleManagementModel returnValue = new RoleManagementModel();
                returnValue.UserId = selectedProfile.UserId;
                foreach (webpages_Roles role in selectedProfile.webpages_Roles)
                {
                    switch (role.RoleName)
                    {
                        case "Root":
                            returnValue.Root = true;
                            break;
                        case "Administrator":
                            returnValue.Administrator = true;
                            break;
                        case "Moderator":
                            returnValue.Moderator = true;
                            break;
                        case "User":
                            returnValue.User = true;
                            break;
                        case "Announcer":
                            returnValue.Announcer = true;
                            break;
                    }
                }

                return View(returnValue);
            }
        }
Exemplo n.º 29
0
        public ActionResult ViewThread(ForumReplyModel model)
        {
            ViewThreadModel viewThreadModel = new ViewThreadModel()
            {
                Replies = new List<ForumReplyModel>()
            };

            using (CGWebEntities entities = new CGWebEntities())
            {
                UserProfile currentUserProfile = entities.UserProfiles.Where(P => P.UserName.Equals(User.Identity.Name)).Single();

                ForumReply newReply = new ForumReply()
                {
                    CreatedBy = currentUserProfile.UserId,
                    CreatedOn = DateTime.UtcNow,
                    ModifiedOn = null,
                    ParentThreadId = model.ThreadId,
                    ReplyContent = model.ReplyContent,
                    ReplyId = Guid.NewGuid()
                };

                entities.ForumReplies.Add(newReply);
                entities.SaveChanges();
                ModelState.Clear();

                ForumThread currentThread = entities.ForumThreads.Where(FT => FT.ThreadId.Equals(model.ThreadId)).Single();

                viewThreadModel.ParentTopic = currentThread.ParentForumTopic.ConvertToForumTopicModel();

                if (!currentThread.ParentForumTopic.IsPublic && !Request.IsAuthenticated)
                    return RedirectToAction("Login", "Account");

                int currentPagingLimit = Convert.ToInt32(ConfigurationManager.AppSettings["ForumReplyPagingLimit"]);
                viewThreadModel.MaxPages = (int)Math.Ceiling((double)currentThread.ForumReplies.Count / (double)currentPagingLimit);
                viewThreadModel.CurrentPage = viewThreadModel.MaxPages - 1;

                viewThreadModel.CurrentThread = currentThread.ConvertToForumThreadModel(true);

                foreach (ForumReply reply in currentThread.ForumReplies.OrderBy(FR => FR.CreatedOn).Skip(viewThreadModel.CurrentPage * currentPagingLimit).Take(currentPagingLimit))
                {
                    viewThreadModel.Replies.Add(reply.ConvertToThreadReplyModel(true));
                }
            }

            return View(viewThreadModel);
        }