Exemplo n.º 1
0
        //public IEnumerable<News> GetNewsByCategory(int CategoryId)
        //{
        //}
        public IEnumerable <News> GetAllNews()
        {
            var db   = new EstiemPortalContext();
            var news = from m in db.NEWS_News
                       orderby m.Id descending
                       select new News
            {
                Id          = m.Id,
                Title       = m.Title,
                ImageUrl    = m.ImageUrl,
                Author      = m.Author,
                Created     = m.Created,
                IsPublished = m.IsPublished,
                Preview     = m.Preview,
                Priority    = m.Priority,
                Text        = m.Text,
                Updated     = m.Updated,
                Categories  = from a in db.NEWS_NewsCategories
                              join b in db.NEWS_Category
                              on a.CategoryId equals b.Id
                              where a.NewsId == m.Id
                              select new NewsCategory
                {
                    CategoryId = a.CategoryId,
                    Name       = b.Name
                }
            };

            return(news);
        }
Exemplo n.º 2
0
        public ActionResult _LoggedInList()
        {
            var lgs = LocalGroupRepository.GetActiveLocalGroups();
            var db  = new EstiemPortalContext();

            var lgids = from s in db.ESTIEM_LocalGroup
                        select s.Id;

            var logged = from s in db.ESTIEM_LocalGroup
                         where s.Status == 1 // Make an enum for LocalGroupStatuses
                         select new StatsViewModel()
            {
                Name = s.Name,
                LoggedInLastMonth = (from m in db.PORTAL_PortalUser
                                     join a in db.PORTAL_ESTIEMUser on m.UserId equals a.UserId
                                     where SqlFunctions.DateDiff("day", m.LastLogin, DateTime.Now) < 30 &&
                                     a.LocalGroupId == s.Id
                                     select m.UserId).Count(),
                LoggedInLast3Months = (from m in db.PORTAL_PortalUser
                                       join a in db.PORTAL_ESTIEMUser on m.UserId equals a.UserId
                                       where SqlFunctions.DateDiff("day", m.LastLogin, DateTime.Now) < 90 &&
                                       a.LocalGroupId == s.Id
                                       select m.UserId).Count(),
                LoggedInLastYear = (from m in db.PORTAL_PortalUser
                                    join a in db.PORTAL_ESTIEMUser on m.UserId equals a.UserId
                                    where SqlFunctions.DateDiff("day", m.LastLogin, DateTime.Now) < 365 &&
                                    a.LocalGroupId == s.Id
                                    select m.UserId).Count()
            };

            return(PartialView(logged));
        }
Exemplo n.º 3
0
        public Event GetEventById(int evid)
        {
            var db = new EstiemPortalContext();
            var ev = (from m in db.EVENTS_Events
                      where m.Id == evid
                      select new Event
            {
                Id = m.Id,
                EventType = m.EventType,
                Name = m.Name,
                Description = m.Description,
                StartDate = m.StartDate,
                EndDate = m.EndDate,
                ApplicationStartDate = m.ApplicationStartDate,
                ApplicationEndDate = m.ApplicationEndDate,
                Place = m.Place,
                ParticipationFee = m.ParticipationFee,
                MaxParticipants = m.Maxparticipants,
                CancellationDeadLine = m.RetireDeadline,
                HomePage = m.HomePage,
                Facebook = m.Facebook,
                Email = m.Email,
                RegistrationMode = m.RegistrationMode,
                NumberOfRegistered = (from s in db.EVENTS_Participants
                                      where s.RegistrationStatus == 0 && s.EventID == m.Id
                                      select s.UserId).Count()
            }).Single();

            return(ev);
        }
Exemplo n.º 4
0
        public IEnumerable <Event> GetAllEvents()
        {
            var db  = new EstiemPortalContext();
            var evs = from m in db.EVENTS_Events
                      orderby m.StartDate
                      select new Event
            {
                Id                   = m.Id,
                EventType            = m.EventType,
                Name                 = m.Name,
                Description          = m.Description,
                StartDate            = m.StartDate,
                EndDate              = m.EndDate,
                ApplicationStartDate = m.ApplicationStartDate,
                ApplicationEndDate   = m.ApplicationEndDate,
                Place                = m.Place,
                ParticipationFee     = m.ParticipationFee,
                MaxParticipants      = m.Maxparticipants,
                CancellationDeadLine = m.RetireDeadline,
                HomePage             = m.HomePage,
                Facebook             = m.Facebook,
                Email                = m.Email,
                RegistrationMode     = m.RegistrationMode,
                NumberOfRegistered   = (from s in db.EVENTS_Participants
                                        where s.RegistrationStatus == 0 && s.EventID == m.Id
                                        select s.UserId).Count()
            };

            return(evs);
        }
Exemplo n.º 5
0
        public void EditEvent(Event ev)
        {
            var db = new EstiemPortalContext();

            db.Entry(ev).State = EntityState.Modified;
            db.SaveChanges();
        }
Exemplo n.º 6
0
        public ActionResult Index(int userid)
        {
            int CurrentUserId    = Int32.Parse(User.Identity.GetUserId());
            var db               = new EstiemPortalContext();
            var ProfileViewModel = (from p in db.PORTAL_ESTIEMUser
                                    where p.UserId == userid
                                    select new ProfileViewModel
            {
                UserId = userid,
                LocalGroup = (from s in db.ESTIEM_LocalGroup
                              where s.Id == p.LocalGroupId
                              select s.Name).FirstOrDefault(),
                Name = p.FirstNameEnglish + " " + p.LastNameEnglish,
                BirthDay = p.Birthday,
                NickName = p.NickName,
                Interests = p.Interests,
                StudyInformation = p.StudyInfo,
                StudiesStart = p.StudiesStart,
                AttendedEvents = (from s in db.EVENTS_Participants
                                  // Shows events where status is registered or organizer
                                  // Make an enum out of this
                                  where (s.RegistrationStatus == 0 || s.RegistrationStatus == 5) &&
                                  s.UserId == p.UserId
                                  orderby s.EVENTS_Events.StartDate descending
                                  select s.EVENTS_Events).ToList()
            }).Single();

            return(View(ProfileViewModel));
        }
Exemplo n.º 7
0
        public static IEnumerable <FriendsViewModel> GetFriendsForUser(int UserId)
        {
            var db = new EstiemPortalContext();
            // Gets the events you have been to excluding Council Meetings
            var evs = from m in db.EVENTS_Participants
                      where m.UserId == UserId && m.RegistrationStatus == 0 && m.CmStatus == 0
                      select m.EventID;

            var lgid = (from m in db.PORTAL_ESTIEMUser
                        where m.UserId == UserId
                        select m.LocalGroupId).FirstOrDefault();

            var friends = from m in db.EVENTS_Participants
                          where evs.Contains(m.EventID) && m.RegistrationStatus == 0
                          select m.UserId;

            var ownlg = from e in db.PORTAL_ESTIEMUser
                        where e.LocalGroupId == lgid
                        select e.UserId;

            var fvm = (from m in db.EVENTS_Participants
                       where friends.Contains(m.UserId) || ownlg.Contains(m.UserId)
                       orderby m.RegistrationDate descending
                       select new FriendsViewModel
            {
                Name = (from a in db.PORTAL_User where a.Id == m.UserId select a.UserName).FirstOrDefault(),
                UserId = m.UserId,
                EventName = m.EVENTS_Events.Name,
                EventId = m.EventID
            });

            return(fvm);
        }
        public ActionResult Applicants()
        {
            var             db   = new EstiemPortalContext();
            HTML_HtmlModule html = db.HTML_HtmlModule.FirstOrDefault(d => d.ModuleId == 9589);

            html.Text = HttpUtility.HtmlDecode(html.Text);
            return(View(html));
        }
Exemplo n.º 9
0
        public NewsCategory GetNewsCategory(int id)
        {
            var db       = new EstiemPortalContext();
            var category = (from m in db.NEWS_Category
                            where m.Id == id
                            select new NewsCategory
            {
                CategoryId = m.Id,
                Name = m.Name
            }).FirstOrDefault();

            return(category);
        }
Exemplo n.º 10
0
        public User GetUserById(int id)
        {
            var  db  = new EstiemPortalContext();
            User usr = (from m in db.PORTAL_ESTIEMUser
                        where m.UserId == id
                        select new User
            {
                // Todo: add rest later. Also take a look at which tables the info is currently on
                UserName = m.FirstNameEnglish + " " + m.LastNameEnglish
            }).FirstOrDefault();

            return(usr);
        }
Exemplo n.º 11
0
        public static IEnumerable <LocalGroup> GetActiveLocalGroups()
        {
            var db = new EstiemPortalContext();
            IEnumerable <LocalGroup> lgs = from m in db.ESTIEM_LocalGroup
                                           where m.Status == 0 // Todo: Add Enum for statuses
                                           select new LocalGroup
            {
                //Populate LG Function?
                Id   = m.Id,
                Name = m.Name
            };

            return(lgs);
        }
Exemplo n.º 12
0
        public IEnumerable <LocalGroup> GetAllLocalGroups()
        {
            var db = new EstiemPortalContext();
            // Possibly add API here, functions still the same
            IEnumerable <LocalGroup> lgs = from m in db.ESTIEM_LocalGroup
                                           select new LocalGroup
            {
                //Populate LG Function?
                Id   = m.Id,
                Name = m.Name
            };

            return(lgs);
        }
Exemplo n.º 13
0
        public User GetUser(string UserName)
        {
            // This method gets the user for the authentication
            // Should be a better way of doing this, at least try to get the code out of membership provider
            var db = new EstiemPortalContext();
            var u  = (from m in db.PORTAL_User
                      where m.UserName == UserName
                      select new User {
                UserId = m.Id,
                UserName = m.UserName,
                Password = m.HashPassword
            }).FirstOrDefault();

            return(u);
        }
Exemplo n.º 14
0
        public ActionResult Search(string searchstring, string searchtype)
        {
            var db = new EstiemPortalContext();

            var people = db.PORTAL_ESTIEMUser.
                         Where(x => x.FirstNameEnglish.Contains(searchstring) ||
                               x.LastNameEnglish.Contains(searchstring));

            var events = db.EVENTS_Events.
                         Where(x => x.Name.Contains(searchstring) ||
                               x.Place.Contains(searchstring));

            var localgroups = db.ESTIEM_LocalGroup.
                              Where(x => x.Name.Contains(searchstring));

            return(View(people));
        }
Exemplo n.º 15
0
        public static List <string> GetStartingWords()
        {
            var db = new EstiemPortalContext();
            var applicationtexts = from m in db.EVENTS_Participants
                                   select m.MotivationText;
            var wor = new List <string>();

            foreach (var text in applicationtexts)
            {
                if (!String.IsNullOrWhiteSpace(text))
                {
                    var words = text.Split(null);
                    wor.Add(words[0]);
                }
            }

            return(wor);
        }
Exemplo n.º 16
0
        public LocalGroup GetLocalGroupById(int lgid)
        {
            var db = new EstiemPortalContext();

            // Todo: Update this when changing to new db schema.
            // Add Region as string to table
            // Possibly add API here, functions still the same
            LocalGroup lg = (from m in db.ESTIEM_LocalGroup
                             where m.Id == lgid
                             select new LocalGroup
            {
                //Populate LG Function?
                Id = m.Id,
                Name = m.Name
            }).FirstOrDefault();

            return(lg);
        }
Exemplo n.º 17
0
        public ActionResult _MainMenu()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(PartialView("~/Views/Shared/_MainMenuNotLoggedIn.cshtml"));
            }
            // This method should not be needed if I'm able to fix adding claims
            var db          = new EstiemPortalContext();
            int currentuser = Int32.Parse(User.Identity.GetUserId());
            var mvvm        = (from m in db.PORTAL_ESTIEMUser
                               where m.UserId == currentuser
                               select new MainMenuViewModel()
            {
                Name = m.FirstNameEnglish + " " + m.LastNameEnglish,
                UserId = m.UserId
            }).FirstOrDefault();

            return(PartialView("~/Views/Shared/_MainMenu.cshtml", mvvm));
        }
Exemplo n.º 18
0
        public ActionResult _EventShort()
        {
            var db   = new EstiemPortalContext();
            var evvm = (from m in db.EVENTS_Events
                        where (m.EventType != 12 && m.EventType != 9) && m.ApplicationEndDate > DateTime.Now
                        orderby m.ApplicationEndDate
                        select new EventViewModel()
            {
                EventId = m.Id,
                Name = m.Name,
                StartDate = m.StartDate,
                EndDate = m.EndDate,
                ApplicationStartDate = m.ApplicationStartDate,
                ApplicationEndDate = m.ApplicationEndDate,
                Place = m.Place,
            }).Take(6);

            return(PartialView(evvm));
        }
Exemplo n.º 19
0
        public ActionResult Application(int eventid)
        {
            var db = new EstiemPortalContext();
            //var pvm = (from m in db.EVENTS_Participants
            //                        join User in db.PORTAL_ESTIEMUser on m.UserId equals User.UserId
            //                        join lg in db.ESTIEM_LocalGroup on User.LocalGroupId equals lg.Id
            //                        where m.EventID == eventid
            //                        select new ParticipantsViewModel()
            //                        {
            //                            UserId = User.UserId,
            //                            Name = User.FirstNameEnglish + " " + User.LastNameEnglish,
            //                            LocalGroup = lg.Name,
            //                            RegistrationStatus = m.RegistrationStatus,
            //                            ApplicationDate = m.RegistrationDate,
            //                            MotivationText = m.MotivationText,
            //                            EventName = m.EVENTS_Events.Name

            //                        }).FirstOrDefault();

            var pvm    = new ParticipantsViewModel();
            var evrepo = new EventRepository();

            pvm = (from m in db.EVENTS_Events
                   where m.Id == eventid
                   select new ParticipantsViewModel()
            {
                Vegetarian = null,
                EatPork = null,
                RequireVisa = null
            }).FirstOrDefault();
            pvm.UserId = Int32.Parse(User.Identity.GetUserId());
            pvm.Event  = evrepo.GetEventById(eventid);


            // If registration is not open currently, or registrationmode is not open to public
            // redirect to the events page
            if (pvm.Event.ApplicationEndDate < DateTime.Now || pvm.Event.RegistrationMode != 0)
            {
                Response.Redirect("~/Events/Index");
            }

            return(View(pvm));
        }
Exemplo n.º 20
0
        public ActionResult Participants(int eventid)
        {
            //Todo: Create exception if no eventid
            var db = new EstiemPortalContext();
            var EventParticipants = from m in db.EVENTS_Participants
                                    join User in db.PORTAL_ESTIEMUser on m.UserId equals User.UserId
                                    join lg in db.ESTIEM_LocalGroup on User.LocalGroupId equals lg.Id
                                    where m.EventID == eventid
                                    select new ParticipantsViewModel()
            {
                UserId             = m.UserId,
                Name               = User.FirstNameEnglish + " " + User.LastNameEnglish,
                LocalGroup         = lg.Name,
                RegistrationStatus = m.RegistrationStatus,
                ApplicationDate    = m.RegistrationDate,
                MotivationText     = m.MotivationText,
                EventName          = m.EVENTS_Events.Name
            };

            return(View(EventParticipants));
        }
Exemplo n.º 21
0
        public News GetNewsById(int id)
        {
            var  db   = new EstiemPortalContext();
            News news = (from m in db.NEWS_News
                         where m.Id == id
                         select new News
            {
                Id = m.Id,
                Title = m.Title,
                ImageUrl = m.ImageUrl,
                Author = m.Author,
                Created = m.Created,
                IsPublished = m.IsPublished,
                Preview = m.Preview,
                Priority = m.Priority,
                Text = m.Text,
                Updated = m.Updated
            }).FirstOrDefault();

            return(news);
        }
Exemplo n.º 22
0
        public static Dictionary <string, List <string> > GetMarkovTable()
        {
            var db = new EstiemPortalContext();
            var applicationtexts = from m in db.EVENTS_Participants
                                   select m.MotivationText;
            var wor = new Dictionary <string, List <string> >();

            foreach (var text in applicationtexts)
            {
                if (!String.IsNullOrWhiteSpace(text))
                {
                    var text2 = text.Replace("\r\n", " ");
                    var words = text2.Split(null);
                    for (int i = 0; i < words.Length - 1; ++i)
                    {
                        // IF the key already exists in the dictionary
                        if (wor.ContainsKey(words[i]))
                        {
                            if (i + 1 != words.Length)
                            {
                                wor[words[i]].Add(words[i + 1]);
                            }
                        }
                        // If key doesn't exist add the key
                        else
                        {
                            if (i < words.Length)
                            {
                                var lista = new List <string>();
                                lista.Add(words[i + 1]);
                                wor.Add(words[i], lista);
                            }
                        }
                    }
                }
            }
            wor.Where(p => p.Value.Count() > 10).ToDictionary(p => p.Key, p => p.Value);
            return(wor);
        }
Exemplo n.º 23
0
        public async Task <ActionResult> Application(ParticipantsViewModel pvm)
        {
            // Add the application to the database
            var db  = new EstiemPortalContext();
            var evp = new EVENTS_Participants {
                UserId             = pvm.UserId,
                EventID            = pvm.EventId,
                RegistrationDate   = DateTime.Now,
                RegistrationStatus = 1, // RegistrationStatus 1 means waiting, which is default when applying.
                Comments           = "",
                CmStatus           = 0,
                MotivationText     = pvm.MotivationText,
                Vegetarian         = pvm.Vegetarian,
                NoPork             = pvm.EatPork,
                VisaRequired       = pvm.RequireVisa
            };

            db.EVENTS_Participants.Add(evp);
            db.SaveChanges();
            Response.Redirect("~/Events/Index");
            // Post application info to Slack
            string urlWithAccessToken = "https://hooks.slack.com/services/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";
            Slack  slack   = new Slack(urlWithAccessToken);
            var    evrepo  = new EventRepository();
            Event  ev      = evrepo.GetEventById(pvm.EventId);
            var    usrrepo = new UserRepository();
            User   usr     = usrrepo.GetUserById(pvm.UserId);
            //slack.PostMessage(username: "******",
            //           text: usr.UserName + " applied for " + ev.Name,
            //           channel: "#estiem-mobile");
            // Slack invite to channel
            // Invite applying user to the group of the event
            // Should this be applying or after registration?
            string parameters = "?token=" + System.Configuration.ConfigurationManager.AppSettings["SlackToken"] + "?name=" + pvm.Event.Name;
            var    resp       = await slack.PostToSlack("groups.invite", parameters);

            return(View());
        }