public bool SubmitAnswer(string UserID, int EventID, int SnippetID, string Answer)
        {
            DateTime currentTime = DateHelper.GetCurrentTime();

            var snippetTemp = db.Snippets.Find(SnippetID);
            var ev          = db.Events.Find(EventID);

            if (snippetTemp != null && ev != null)
            {
                var initialAnswer = db.Answers.FirstOrDefault(x => x.Snippet.ID == snippetTemp.ID && x.User.Id == UserID && ev.ID == x.Event.ID);

                if (initialAnswer == null)
                {
                    return(false);
                }

                var timeElapsed = (int)(currentTime - initialAnswer.DateCreated).TotalSeconds;

                if (snippetTemp.Output == Answer)
                {
                    initialAnswer.isCorrect = true;
                }

                initialAnswer.timeElapsed = timeElapsed;
                initialAnswer.answered    = true;
                var res = db.SaveChanges();
                return(res > 0);
            }

            return(false);
        }
Exemple #2
0
        public int RemoveSnippetFromGroup(int SnippetID, int GroupID)
        {
            Group   group            = db.Groups.Where(x => x.ID == GroupID).Include(x => x.Snippets).FirstOrDefault();
            Snippet snippetFromGroup = group.Snippets.FirstOrDefault(x => x.ID == SnippetID);

            group.Snippets.Remove(snippetFromGroup);
            int res = db.SaveChanges();

            return(res);
        }
Exemple #3
0
        public bool AddOrUpdateEvent(Event ev, List <Int32> IDs)
        {
            int res;

            List <EventSnippets> snippetEvents = new List <EventSnippets>();

            for (int i = 0; i < IDs.Count; i++)
            {
                EventSnippets snippetEvent = new EventSnippets
                {
                    SnippetID   = IDs[i],
                    OrderNumber = i + 1
                };
                snippetEvents.Add(snippetEvent);
            }


            if (ev.ID > 0)
            {
                Event eventToUpdate = db.Events.Where(x => x.ID == ev.ID).Include(x => x.EventSnippets).FirstOrDefault();
                db.EventSnippets.RemoveRange(eventToUpdate.EventSnippets);
                res = db.SaveChanges();
                eventToUpdate.Name                   = ev.Name;
                eventToUpdate.Description            = ev.Description;
                eventToUpdate.Start                  = ev.Start;
                eventToUpdate.End                    = ev.End;
                snippetEvents.ForEach(x => x.EventID = ev.ID);
                eventToUpdate.EventSnippets          = snippetEvents;
                res = db.SaveChanges();
            }
            else
            {
                ev.EventSnippets = snippetEvents;
                db.Events.Add(ev);
                res = db.SaveChanges();
            }

            return(res > 0);
        }
Exemple #4
0
        public EventSnippets BeginEvent(string UserID, int EventID)
        {
            var checkIfAlreadyFinished = db.UserEvents.Any(x => x.UserID == UserID && x.EventID == EventID && x.Finished);

            if (checkIfAlreadyFinished)
            {
                return(null);
            }

            UserEvents userEvent = new UserEvents
            {
                UserID   = UserID,
                EventID  = EventID,
                Finished = false
            };

            db.UserEvents.Add(userEvent);
            int res = db.SaveChanges();

            var firstSnippet = db.EventSnippets.Include(x => x.Snippet).FirstOrDefault(x => x.EventID == EventID);

            return(firstSnippet);
        }