Example #1
0
        public JsonResult Supporter(Guid termId, CurrentUserInformation currentUser)
        {
            Term word = Session.Load <Term>(termId);

            if (word.Supporters == null)
            {
                word.Supporters = new List <Guid>();
            }

            word.Supporters.Add(currentUser.Id);

            Session.Store(word);

            if (currentUser.IsAuthenticated)
            {
                var user = Session.Load <User>(currentUser.Id);
                user.ReputationPoints += ActionPoints.AddSupport;

                if (user.ActionFeed == null)
                {
                    user.ActionFeed = new List <Web.Models.Action>();
                }
                user.ActionFeed.Add(new Web.Models.Action()
                {
                    Time = DateTime.UtcNow, Type = ActionType.AddSupport, TermIdContext = termId
                });

                Session.Store(user);
            }

            Session.SaveChanges();

            return(Json(word));
        }
Example #2
0
        public ActionResult Profile(CurrentUserInformation currentUser)
        {
            var user = Session.Load <User>(currentUser.Id);

            //var result = Session.Query<UserActivityFeedIndex.UserFeedResult, UserActivityFeedIndex>().Where(x => x.Name == currentUser.Name).ToList(); ;

            return(View(user));
        }
Example #3
0
        public ActionResult Reaction(CreateReactionModel model, CurrentUserInformation currentUser)
        {
            Term word = Session.Load <Term>(model.TermId);

            Reaction reaction = new Reaction();

            reaction.Id         = Guid.NewGuid();
            reaction.CreatedOn  = DateTime.UtcNow;
            reaction.Name       = model.Name;
            reaction.Reason     = model.Reason;
            reaction.Title      = model.Title;
            reaction.IsPositive = model.IsPositive;

            ActionType forUserFeed = ActionType.AddGoodReaction;

            if (reaction.IsPositive)
            {
                word.UpVotes = word.UpVotes + 1;
            }
            else
            {
                word.DownVotes = word.DownVotes + 1;
                forUserFeed    = ActionType.AddBadReaction;
            }

            if (word.Reactions == null)
            {
                word.Reactions = new List <Reaction>();
            }
            word.Reactions.Add(reaction);

            if (currentUser.IsAuthenticated)
            {
                reaction.Name           = currentUser.Name;
                reaction.SharedByUserId = currentUser.Id;
                var user = Session.Load <User>(currentUser.Id);
                user.ReputationPoints += ActionPoints.AddReaction;

                if (user.ActionFeed == null)
                {
                    user.ActionFeed = new List <Web.Models.Action>();
                }
                user.ActionFeed.Add(new Web.Models.Action()
                {
                    Time = DateTime.UtcNow, Type = forUserFeed, ReactionIdContext = reaction.Id, TermIdContext = model.TermId
                });

                Session.Store(user);
            }

            Session.Store(word);
            Session.SaveChanges();
            return(RedirectToAction("Detail", new { slug = word.Slug }));
        }
Example #4
0
        public JsonResult Add(CreateResourceModel model, CurrentUserInformation currentUser)
        {
            Term word = Session.Load <Term>(model.TermId);

            Resource resource = new Resource();

            resource.Id           = Guid.NewGuid();
            resource.CreatedOn    = DateTime.UtcNow;
            resource.Title        = model.Title;
            resource.Description  = model.Description;
            resource.Url          = model.Url;
            resource.EmbedCode    = model.EmbedCode;
            resource.ThumbnailUrl = model.Thumbnail;
            resource.Type         = model.Type;
            resource.ViaSource    = model.ViaSource;

            if (word.Resources == null)
            {
                word.Resources = new List <Resource>();
            }
            word.Resources.Add(resource);

            if (currentUser.IsAuthenticated)
            {
                resource.SharedByUserId = currentUser.Id;
                var user = Session.Load <User>(currentUser.Id);
                user.ReputationPoints += ActionPoints.AddInformation;

                if (user.ActionFeed == null)
                {
                    user.ActionFeed = new List <Web.Models.Action>();
                }
                user.ActionFeed.Add(new Web.Models.Action()
                {
                    Time = DateTime.UtcNow, Type = ActionType.AddInformation, ResourceIdContext = resource.Id, TermIdContext = model.TermId
                });

                Session.Store(user);
            }

            Session.Store(word);
            Session.SaveChanges();

            // Pingback for blogger
            UrlHelper helper = new UrlHelper(this.ControllerContext.RequestContext);
            var       source = helper.Action("Detail", "Term", new { Slug = word.Slug }, "http");

            Pingback.Send(new Uri(source), new Uri(resource.Url));

            return(Json(word));
        }
Example #5
0
        public ActionResult Index(CurrentUserInformation currentUser)
        {
            IndexViewModel model = new IndexViewModel();

            model.Top         = Session.Query <Term>().OrderByDescending(x => x.UpVotes).Take(3).ToList();
            model.Bottom      = Session.Query <Term>().OrderByDescending(x => x.DownVotes).Take(3).ToList();
            model.Newest      = Session.Query <Term>().OrderByDescending(x => x.CreatedOn).Take(3).ToList();
            model.NewestUsers = Session.Query <User>().OrderByDescending(x => x.RegisteredOn).Take(15).ToList();

            if (currentUser.IsAuthenticated)
            {
                model.UserName = currentUser.Name;
            }
            return(View(model));
        }
        public IActionResult GetCurrentUserInformation()
        {
            var result = new CurrentUserInformation
            {
                DefaultSeason = new EntityInfoDto
                {
                    Id   = 6,
                    Name = "2019-2020"
                },
                DefaultTeam = new EntityInfoDto
                {
                    Id   = 27,
                    Name = "Kazio"
                }
            };

            return(this.Ok(result));
        }
Example #7
0
        public ActionResult Share(Term term, CurrentUserInformation currentUser)
        {
            if (string.IsNullOrWhiteSpace(term.Title))
            {
                return(Json(false));
            }

            term.Id        = Guid.NewGuid();
            term.CreatedOn = DateTime.UtcNow;
            term.LcId      = "1033";
            term.Slug      = SearchForSlug(term.Title);

            if (currentUser.IsAuthenticated)
            {
                term.SharedByUserId = currentUser.Id;
                var user = Session.Load <User>(currentUser.Id);
                user.ReputationPoints += ActionPoints.ShareANewTerm;

                if (user.ActionFeed == null)
                {
                    user.ActionFeed = new List <Action>();
                }
                user.ActionFeed.Add(new Action()
                {
                    Time = DateTime.UtcNow, Type = ActionType.ShareANewTerm, TermIdContext = term.Id
                });

                Session.Store(user);
            }

            Session.Store(term);
            Session.SaveChanges();

            string  url    = Url.Action("Detail", "Term", new { area = "Wiki", slug = term.Slug });
            dynamic result = new { ToTermUrl = url };

            return(Json(result));
        }
Example #8
0
        public ViewResult Detail(string slug, CurrentUserInformation currentUser)
        {
            //ToDo: Number of Request 2 - not 1. Include doesn´t work.
            Term word = Session.Query <Term>().Where(x => x.Slug == slug)
                        .SingleOrDefault();

            word.Views = word.Views + 1;
            Session.Store(word);

            DetailTermViewModel model = new DetailTermViewModel();

            if (word.Supporters != null)
            {
                model.Supporters = Session.Query <User>().Where(x => x.Id.In(word.Supporters)).ToList();
            }
            else
            {
                model.Supporters = new List <User>();
            }

            model.Id        = word.Id;
            model.Views     = word.Views;
            model.Title     = word.Title;
            model.DownVotes = word.DownVotes;
            model.UpVotes   = word.UpVotes;
            model.Slug      = word.Slug;
            model.CreatedOn = word.CreatedOn.ToShortDateString();
            model.Resources = new List <DetailResourceViewModel>();
            if (word.Resources != null)
            {
                foreach (var resource in word.Resources)
                {
                    DetailResourceViewModel viewModelForResource = new DetailResourceViewModel();
                    viewModelForResource.Title       = resource.Title;
                    viewModelForResource.Url         = resource.Url;
                    viewModelForResource.Description = resource.Description;
                    viewModelForResource.Votes       = resource.Upvotes - resource.Downvotes;
                    if (resource.Type == "link")
                    {
                        viewModelForResource.Thumbnail = "http://image.thumber.de/?size=L&url=" + resource.Url;
                    }
                    else
                    {
                        viewModelForResource.Thumbnail = resource.ThumbnailUrl;
                    }
                    viewModelForResource.Html = resource.EmbedCode;
                    model.Resources.Add(viewModelForResource);
                }
            }
            if (word.Reactions != null)
            {
                model.PositiveReaction = word.Reactions.Where(x => x.IsPositive == true).ToList();
                model.NegativeReaction = word.Reactions.Where(x => x.IsPositive == false).ToList();
            }
            else
            {
                model.PositiveReaction = new List <Reaction>();
                model.NegativeReaction = new List <Reaction>();
            }

            model.CurrentUserInformation = currentUser;

            return(View(model));
        }