private AssignmentSubmission completeAssignment(Assignment assignment, string userId, bool accepted) { var mySubmission = _context.AssignmentSubmissions.FirstOrDefault(a => a.UserId == userId && a.AssignmentId == assignment.Id); if (mySubmission != null) { mySubmission.Accepted = accepted; } else { var submission = new AssignmentSubmission() { AssignmentId = assignment.Id, UserId = userId, Timestamp = DateTime.Now, PointsRecieved = assignment.Points, Accepted = accepted }; _context.AssignmentSubmissions.Add(submission); mySubmission = submission; } _context.SaveChanges(); return(mySubmission); }
public PollVM CreatePoll(string dictaatName, PollVM poll) { Poll p = new Poll(); p.Question = poll.Question; p.DictaatName = dictaatName; p.Options = poll.Options.Select(o => new PollOption() { Text = o.Text }).ToList(); _context.Polls.Add(p); _context.SaveChanges(); return(new PollVM(p)); }
public DictaatRepositoryTest() { var options = new DbContextOptionsBuilder <WebdictaatContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; context = new WebdictaatContext(options); context.DictaatDetails.Add(new Domain.DictaatDetails() { Name = "Test 1", DictaatOwnerId = "1" }); context.DictaatDetails.Add(new Domain.DictaatDetails() { Name = "Test 2", DictaatOwnerId = "2" }); context.Users.Add(new Domain.User.ApplicationUser() { Id = "1", FullName = "User A" }); context.Users.Add(new Domain.User.ApplicationUser() { Id = "2", FullName = "User B" }); context.SaveChanges(); _r = new Models.DictaatRepository(_config.Object, null, null, context); }
public UserAchievement AddUserAchievement(int achievementid, string userid) { var user = _context.Users.FirstOrDefault(a => a.Id == userid); var achievement = _context.Achievements.FirstOrDefault(a => a.Id == achievementid); var date = DateTime.Now; var userachievement = new UserAchievement(); userachievement.User = user; userachievement.UserId = user.Id; userachievement.Achievement = achievement; userachievement.AchievementId = achievement.Id; userachievement.Timestamp = date; _context.UserAchievements.Add(userachievement); _context.SaveChanges(); return(userachievement); }
public RateVM CreateRate(int ratingId, string userId, RateVM rate) { var r = new Rate() { Emotion = (int)rate.Emotion, Feedback = rate.Feedback, Timestamp = DateTime.Now, UserId = userId, }; Rating rating = _context.Ratings .Include(ra => ra.Rates) .FirstOrDefault(q => q.Id == ratingId); rating.Rates.Add(r); _context.SaveChanges(); rate.Id = r.Id; return(rate); }
/// <summary> /// Create a new dictaat based on a given template. /// </summary> /// <param name="name">Name of the dictaat. Must be unique.</param> /// <param name="template">optional template name, default = defaultTemplate</param> public void CreateDictaat(string name, ApplicationUser user, string template) { //Create the database entry var dictaatDetails = new DictaatDetails() { Name = name, DictaatOwnerId = user.Id, IsEnabled = false, //by default we don't show the dictaten }; var dictaatSession = new DictaatSession() { DictaatDetailsId = name, StartedOn = DateTime.Now, }; _context.DictaatSession.Add(dictaatSession); _context.DictaatDetails.Add(dictaatDetails); _context.SaveChanges(); //Create the folder Domain.Dictaat dictaat = _dictaatFactory.CreateDictaat(name, template); }
public QuizVM AddAttempt(int quizId, string userId, IEnumerable <QuestionAttemptVM> attempt) { var quiz = _context.Quizes.FirstOrDefault(q => q.Id == quizId); QuizAttempt qa = new QuizAttempt() { QuizId = quizId, UserId = userId, Timestamp = DateTime.Now, QuestionsAnswered = attempt.ToList().Select(a => a.ToPoco()).ToList() }; //if all questions are correct, complete assignment if available if (!qa.QuestionsAnswered.Any(q => !q.IsCorrect) && quiz.AssignmentId.HasValue) { _assignmentRepo.CompleteAssignment(quiz.AssignmentId.Value, userId, true); } _context.QuizAttempts.Add(qa); _context.SaveChanges(); return(this.GetQuiz(quizId, userId)); }
/// <summary> /// Join the current session of a dictaat /// </summary> /// <param name="dictaatName"></param> /// <param name="groupName"></param> /// <param name="userId"></param> /// <returns></returns> public bool Join(string dictaatName, string groupName, string userId) { var currentSession = _context.DictaatSession .Include(s => s.Participants) .FirstOrDefault(s => s.EndedOn == null && s.DictaatDetailsId == dictaatName); var group = _context.DictaatGroup.FirstOrDefault(dg => dg.DictaatName == dictaatName && dg.Name == groupName); var participant = currentSession.Participants.FirstOrDefault(p => p.UserId == userId); if (participant == null) { participant = new DictaatSessionUser() { UserId = userId }; currentSession.Participants.Add(participant); } participant.Group = group != null ? group.Name : null; participant.DictaatName = group != null ? currentSession.DictaatDetailsId : null; _context.SaveChanges(); return(true); //Joined this ditaat :D }
public static void CreateQuizes(WebdictaatContext context) { context.Quizes.Add(new Quiz() //Quiz 1 { Id = 11, Title = "Title", Description = "Desc", Questions = new List <QuestionQuiz>() { new QuestionQuiz() { QuestionId = 11 }, new QuestionQuiz() { QuestionId = 12 } } }); context.SaveChanges(); }
public QuestionVM CreateQuestion(QuestionVM question) { _context.Questions.Add(question.ToPoco()); _context.SaveChanges(); return(question); }