Esempio n. 1
0
        public async Task <IActionResult> Ask(JoinEventViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(RedirectToAction("Join", new { code = model.EventCode }));
            }

            var qn = this.service.CreateQuestion(model);

            if (qn == null)
            {
                return(RedirectToAction("Join", new { code = model.EventCode }));
            }

            this.service.SaveQuestion(qn);

            if (qn.IsReviewed)
            {
                await this.hubContext.Clients.Group(model.EventCode)
                .SendAsync("Callback", qn.Content, qn.PublishedOn.ToShortDateString(), qn.AuthorName, qn.Id, model.EventId, model.EventCode);
            }

            await this.hubContext.Clients.Group(model.EventCode)
            .SendAsync("ForManager", qn.Content, qn.PublishedOn.ToShortDateString(), qn.AuthorName, qn.Id);


            return(RedirectToAction("Join", new { code = model.EventCode }));
        }
Esempio n. 2
0
        public async Task <IActionResult> JoinEvent(int id)
        {
            var evt = await _dbContext.Events.FindAsync(id);

            if (evt == null)
            {
                // TODO: Diplay error
                return(RedirectToAction(nameof(Index)));
            }

            // TODO: Handle guest users (remove auth attribute)
            var currentUser = await _userManager.GetUserAsync(User);

            var model = new JoinEventViewModel();

            model.Event = evt.ToModel();
            model.IsCurrentUserMember = await _dbContext.EventMembers.AnyAsync(x => x.EventId == evt.Id && x.UserId == currentUser.Id);

            if (model.IsCurrentUserMember)
            {
                return(RedirectToAction(nameof(Details), new { slug = evt.Slug }));
            }

            return(View(model));
        }
Esempio n. 3
0
        public async Task <IActionResult> Ask(JoinEventViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(RedirectToAction("Join", new { code = model.EventCode }));
            }

            var question = new Question()
            {
                EventId     = model.EventId,
                Content     = model.Content,
                PublishedOn = DateTime.Now
            };

            if (model.ParticipantId == null)
            {
                var anonimous = await userManager.FindByNameAsync("Anonimous");

                question.AuthorId = anonimous.Id;
            }
            else
            {
                question.AuthorId = model.ParticipantId;
            }

            this.db.Questions.Add(question);

            this.db.SaveChanges();

            return(RedirectToAction("Join", new { code = model.EventCode }));
        }
        public QuestionViewModel GetQuestionModel(JoinEventViewModel model)
        {
            var questionModel = new QuestionViewModel()
            {
                AuthorName  = model.Question.ParticipantName,
                PublishedOn = model.Question.PublishedOn,
                Content     = model.Question.Content
            };

            return(questionModel);
        }
Esempio n. 5
0
        public async Task <IActionResult> JoinEvent(int id, JoinEventViewModel model)
        {
            var evt = await _dbContext.Events.FindAsync(id);

            if (evt == null)
            {
                _logger.LogInformation($"Event ID {id} not found");

                // TODO: Display error
                return(RedirectToAction(nameof(Index)));
            }

            model.Event = evt.ToModel();

            var currentUser = await _userManager.GetUserAsync(User);

            var userIsMember = await _dbContext.EventMembers.AnyAsync(x => x.EventId == evt.Id && x.UserId == currentUser.Id);

            if (userIsMember)
            {
                _logger.LogInformation($"User ID {currentUser.Id} is already member of Event ID {evt.Id}");

                return(RedirectToAction(nameof(Details), new { slug = evt.Slug }));
            }

            if (evt.RequirePassword && model.Password != evt.JoinPassword)
            {
                ModelState.AddModelError(nameof(model.Password), "Event password is invalid");
                return(View(model));
            }

            try
            {
                var member = new EventMember
                {
                    EventId    = evt.Id,
                    UserId     = currentUser.Id,
                    JoinDate   = DateTime.UtcNow,
                    JoinMethod = EventMemberJoinMethod.Password
                };

                _dbContext.EventMembers.Add(member);
                await _dbContext.SaveChangesAsync();

                // TODO: show success message
                return(RedirectToAction(nameof(Details), new { slug = evt.Slug }));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error joining user ID {currentUser.Id} to event ID {evt.Id}");
                return(View(model));
            }
        }
Esempio n. 6
0
        public IActionResult Join(string code)
        {
            if (code == null)
            {
                return(LocalRedirect("~/"));
            }

            var dbEvent = this.db.Events.FirstOrDefault(e => e.Code == code);

            if (dbEvent == null)
            {
                return(LocalRedirect("~/NoResult"));
            }

            var questions = this.db.Questions
                            .Where(q => q.EventId == dbEvent.Id)
                            .Select(q => new QuestionViewModel()
            {
                AuthorName  = q.Author.UserName,
                Content     = q.Content,
                Upvotes     = q.Upvotes,
                PublishedOn = q.PublishedOn,
                Doqwnvotes  = q.Downvotes,
                Replies     = q.Replies
                              .Select(r => new ReplyViewModel()
                {
                    AuthorName = r.Author.UserName,
                    Content    = r.Content,
                    Upvotes    = r.Upvotes,
                    Downvotes  = r.Downvotes
                }).ToList()
            })
                            .ToList();


            var joinModel = new JoinEventViewModel()
            {
                EventId    = dbEvent.Id,
                EventTitle = dbEvent.Title,
                EventCode  = dbEvent.Code
            };

            joinModel.Questions = questions;

            joinModel.IsAnonimous = true;

            if (this.User.IsInRole(RoleType.Manager))
            {
                joinModel.ParticipantId = this.userManager.GetUserId(User);
            }

            return(View(joinModel));
        }
        public void WithValidModelReturnsQuestionViewModel()
        {
            var question = new QuestionBindingModel()
            {
                Content = "Test question"
            };

            var model = new JoinEventViewModel()
            {
                EventId = 1, Question = question
            };

            var result = this.service.GetQuestionModel(model);

            Assert.AreEqual(typeof(QuestionViewModel), result.GetType());
        }
Esempio n. 8
0
        public async Task QuestionsServer(JoinEventViewModel model)
        {
            this.service.SetPublishedOn(model);

            var question = this.service.CreateQuestion(model);

            this.service.SaveQuestion(question);

            var questionModel = this.service.GetQuestionModel(model);

            await this.hubContext.Clients.Group(model.EventCode).SendAsync("Callback", "Hello", "From server");

            //await this.hubContext.Clients.All.SendAsync("Callback", questionModel.Content, questionModel.AuthorName);

            return;
        }
        public async Task <IActionResult> Join(JoinEventViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = await _participantsService.RegisterParticipantAsync(model.Code, User.GetNameIdentifier());

            if (result.Type != ResultStatusType.Ok)
            {
                AddModelErrors(result);
                return(View(model));
            }

            return(RedirectToAction(nameof(EventsController.Details), "Events", new
            {
                Id = result.Object
            }));
        }
        public Question CreateQuestion(JoinEventViewModel model)
        {
            var dbEvent = this.db.Events.FirstOrDefault(e => e.Id == model.EventId &&
                                                        e.IsClosed == false &&
                                                        e.IsDeleted == false);

            if (dbEvent == null)
            {
                return(null);
            }

            var question = new Question()
            {
                EventId     = model.EventId,
                Content     = model.Question.Content,
                PublishedOn = DateTime.Now
            };

            if (dbEvent.IsModerated)
            {
                question.IsReviewed = false;
            }
            else
            {
                question.IsReviewed = true;
            }

            if (model.Question.ParticipantName != null)
            {
                question.AuthorName = model.Question.ParticipantName;
            }
            else
            {
                question.AuthorName = VoteConstants.Anonymous;
            }

            return(question);
        }
        public JoinEventViewModel CreateEventModel(EventViewModel eventModel)
        {
            var questions = new List <QuestionFullModel>();

            if (eventModel.IsModerated)
            {
                questions = this.db.Questions
                            .Where(q => q.EventId == eventModel.Id &&
                                   q.IsReviewed == true &&
                                   q.IsArchived == false &&
                                   q.IsDeleted == false)
                            .Select(q => new QuestionFullModel()
                {
                    Id          = q.Id,
                    AuthorName  = q.AuthorName,
                    Content     = q.Content,
                    Upvotes     = q.Upvotes,
                    PublishedOn = q.PublishedOn.ToShortDateString(),
                    Doqwnvotes  = q.Downvotes,
                    Replies     = q.Replies
                                  .Select(r => new ReplyViewModel()
                    {
                        AuthorName = r.AuthorName,
                        Content    = r.Content
                    }).ToList()
                })
                            .ToList();
            }
            else
            {
                questions = this.db.Questions
                            .Where(q => q.EventId == eventModel.Id &&
                                   q.IsArchived == false &&
                                   q.IsDeleted == false)
                            .Select(q => new QuestionFullModel()
                {
                    Id          = q.Id,
                    AuthorName  = q.AuthorName,
                    Content     = q.Content,
                    Upvotes     = q.Upvotes,
                    PublishedOn = q.PublishedOn.ToShortDateString(),
                    Doqwnvotes  = q.Downvotes,
                    Replies     = q.Replies
                                  .Select(r => new ReplyViewModel()
                    {
                        AuthorName = r.AuthorName,
                        Content    = r.Content
                    }).ToList()
                })
                            .ToList();
            }

            var creator = this.db.Users.Find(eventModel.CreatorId);

            string logoFileName = "DefaultLog.jpg";

            if (creator.HasLogo)
            {
                logoFileName = creator.Id + ".jpg";
            }

            var joinModel = new JoinEventViewModel()
            {
                EventId      = eventModel.Id,
                EventCode    = eventModel.Code,
                EventTitle   = eventModel.Title,
                Questions    = questions,
                LogoFileName = logoFileName
            };

            return(joinModel);
        }
 public void SetPublishedOn(JoinEventViewModel model)
 {
     model.Question.PublishedOn = DateTime.Now;
 }