Beispiel #1
0
        public async Task <ActionResult <bool> > DeleteToDoItems(int Id)
        {
            var itemToRemove = await _context.TodoItems.FindAsync(Id);

            if (itemToRemove == null)
            {
                return(false);
            }
            _context.TodoItems.Remove(itemToRemove);
            _context.SaveChanges();
            return(true);
        }
        public ActionResult Edit(StudySubjectViewModel model)
        {
            var identity = (ClaimsIdentity)User.Identity;
            var idString = identity.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier)
                           .Select(c => c.Value).SingleOrDefault();
            Guid UserId;

            if (Guid.TryParse(idString, out UserId))
            {
                using (JournalContext db = new JournalContext())
                {
                    User user      = db.Users.Find(UserId);
                    var  pupilRole = Guid.Parse(Roles.Pupil);
                    model.Users = db.Users.Where(c => c.UserRollID == pupilRole && c.SchoolID == user.SchoolID).Select(c => new SelectListItem()
                    {
                        Value = c.ID.ToString(), Text = c.FirstName + " " + c.LastName
                    }).ToList();
                    model.Subjects = db.Subjects.Where(c => c.Teacher.SchoolID == user.SchoolID).Select(c => new SelectListItem()
                    {
                        Value = c.ID.ToString(), Text = c.SubjectType.Name
                    }).ToList();
                    if (ModelState.IsValid)
                    {
                        StudySubject studySubject = db.StudySubject.Find(model.ID);
                        studySubject.UserID    = Guid.Parse(model.SelectedUser);
                        studySubject.SubjectID = Guid.Parse(model.SelectedSubject);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    return(View(model));
                }
            }
            return(RedirectToAction("Login"));
        }
Beispiel #3
0
        public IActionResult Create(JournalViewModel journalView)
        {
            if (ModelState.IsValid)
            {
                var fileName = ContentDispositionHeaderValue
                               .Parse(journalView.File.ContentDisposition)
                               .FileName
                               .Trim('"');     // FileName returns "fileName.ext"(with double quotes)

                if (fileName.EndsWith(".pdf")) // Important for security if saving in webroot
                {
                    var journal = Mapper.Map <Journal>(journalView);

                    var publisher = _context.Publishers.FirstOrDefault(x => x.PublisherId == journalView.PublisherId);
                    journal.Publisher = publisher;
                    _context.Journals.Add(journal);
                    _context.SaveChanges();

                    return(RedirectToAction("Manage"));
                }
            }

            ViewBag.CategoryId  = new SelectList(_context.Categories, "CategoryId", "Name", journalView.CategoryId);
            ViewBag.PublisherId = new SelectList(_context.Publishers, "PublisherId", "Name", journalView.PublisherId);
            ModelState.AddModelError(string.Empty, "Invalid file format.  Please use PDF format");

            ConfigureJournal(journalView);
            return(View(journalView));
        }
 public void PersistOperation(OperationDTO operationDTO)
 {
     using (JournalContext db = new JournalContext())
     {
         db.OperationDTOes.Add(operationDTO);
         db.SaveChanges();
     }
 }
 public ActionResult DeleteConfirm(Guid id)
 {
     using (JournalContext db = new JournalContext())
     {
         SubjectType subjectType = db.SubjectTypes.Find(id);
         db.SubjectTypes.Remove(subjectType);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
Beispiel #6
0
 public ActionResult DeleteConfirm(SubjectViewModels model)
 {
     using (JournalContext db = new JournalContext())
     {
         Subject subject = db.Subjects.Find(model.ID);
         db.Subjects.Remove(subject);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
Beispiel #7
0
 public ActionResult UserRole(UserRole userRole)
 {
     using (JournalContext db = new JournalContext())
     {
         userRole.ID = Guid.NewGuid();
         db.UserRoles.Add(userRole);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
 public ActionResult Delete(StudySubjectViewModel model)
 {
     using (JournalContext db = new JournalContext())
     {
         StudySubject studySubject = db.StudySubject.Find(model.ID);
         db.StudySubject.Remove(studySubject);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
Beispiel #9
0
        public IEnumerable <GcItem> Get([FromQuery] string coach)
        {
            //get coach
            List <GcItem> output = new List <GcItem>();
            var           cq     = _context.Coaches.Include(j => j.QuestionList).Where(i => i.Name.ToLower() == coach.ToLower()).ToList();

            if (cq == null)
            {
                output.Add(new GcItem {
                    Content = "Something got scrambled, refresh the browser", Author = coach, compstyle = "coach"
                }); return(output);
            }
            Question nextQ = cq[0].QuestionList[0];

            //new convo
            UserData user = new UserData
            {
                Email     = User.Identity.Name,
                FirstName = User.Identity.Name
            };

            var convo = new Conversation
            {
                UserData = user,
                DateTime = DateTime.Now
            };

            convo.QuestionsAsked = new List <Question>();
            convo.ResponseList   = new List <Response>();

            convo.inProgress = true;
            convo.Coach      = cq[0];

            convo.QuestionsAsked.Add(new Question
            {
                Index        = 1,
                QuestionText = nextQ.QuestionText,
                Type         = nextQ.Type
            });

            convo.SessionTag = Guid.NewGuid().ToString();
            _context.Conversations.Add(convo);
            HttpContext.Session.SetString("convo-" + coach, convo.SessionTag);
            _context.SaveChanges();
            output.Add(new GcItem {
                Content = nextQ.QuestionText, Author = "Coach " + cq[0].Name, compstyle = "coach", Type = nextQ.Type.ToString()
            });
            return(output);
        }
 public ActionResult CreatePointLevel(PointLevelViewModels model)
 {
     using (JournalContext db = new JournalContext())
     {
         if (ModelState.IsValid)
         {
             PointLevel pointLevel = (PointLevel)model;
             pointLevel.ID = Guid.NewGuid();
             db.PointLevels.Add(pointLevel);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(model));
     }
 }
 public ActionResult Create(StudySubjectViewModel model)
 {
     using (JournalContext db = new JournalContext())
     {
         if (ModelState.IsValid)
         {
             StudySubject studySubject = (StudySubject)model;
             studySubject.ID = Guid.NewGuid();
             db.StudySubject.Add(studySubject);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     return(View(model));
 }
 public ActionResult Edit(SubjectTypeViewModels model)
 {
     using (JournalContext db = new JournalContext())
     {
         if (ModelState.IsValid)
         {
             SubjectType subjectType = db.SubjectTypes.Find(model.ID);
             subjectType.Name        = model.Name;
             subjectType.Description = model.Description;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     return(View(model));
 }
 public ActionResult Create(SubjectTypeViewModels model)
 {
     using (JournalContext db = new JournalContext())
     {
         if (ModelState.IsValid)
         {
             SubjectType subjectType = (SubjectType)model;
             subjectType.ID = Guid.NewGuid();
             db.SubjectTypes.Add(subjectType);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(model));
     }
 }
Beispiel #14
0
 public ActionResult Edit(ClassViewModels model)
 {
     using (JournalContext db = new JournalContext())
     {
         if (ModelState.IsValid)
         {
             Class newmodel = db.Classes.Find(model.ID);
             newmodel.Name = model.Name;
             newmodel.Year = model.Year;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(model));
     }
 }
Beispiel #15
0
 public ActionResult DeleteConfirmed(Guid id)
 {
     using (JournalContext db = new JournalContext())
     {
         Class newClass          = db.Classes.Find(id);
         var   userToUpdateClass = db.Users.Where(c => c.ClassID == newClass.ID);
         foreach (User user in userToUpdateClass)
         {
             user.ClassID = null;
         }
         db.Classes.Remove(newClass);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
Beispiel #16
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            using (JournalContext db = new JournalContext())
            {
                if (ModelState.IsValid)
                {
                    if (db.Users.Any(u => u.Email == model.Email))
                    {
                        model.Roles = db.UserRoles.Select(role => new SelectListItem()
                        {
                            Value = role.ID.ToString(), Text = role.Name
                        }).ToList();
                        model.Schools = db.Schools.Select(school => new SelectListItem()
                        {
                            Value = school.ID.ToString(), Text = school.ShortName
                        }).ToList();
                        model.Classes = db.Classes.Select(@class => new SelectListItem()
                        {
                            Value = @class.ID.ToString(), Text = @class.Name
                        }).ToList();
                        ModelState.AddModelError("Email", "Such email is used. Please choose another.");
                        return(View(model));
                    }
                    User user = (User)model;
                    user.ID           = Guid.NewGuid();
                    user.RegisterDate = DateTime.Now;
                    db.Users.Add(user);
                    db.SaveChanges();


                    return(RedirectToAction("Index", "Home"));
                }
                model.Roles = db.UserRoles.Select(role => new SelectListItem()
                {
                    Value = role.ID.ToString(), Text = role.Name
                }).ToList();
                model.Schools = db.Schools.Select(school => new SelectListItem()
                {
                    Value = school.ID.ToString(), Text = school.ShortName
                }).ToList();
                model.Classes = db.Classes.Select(@class => new SelectListItem()
                {
                    Value = @class.ID.ToString(), Text = @class.Name
                }).ToList();
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult Create(SchoolViewModel model)
        {
            using (JournalContext db = new JournalContext())
            {
                if (ModelState.IsValid)
                {
                    School school = (School)model;
                    school.ID        = Guid.NewGuid();
                    school.TimeStamp = DateTime.Now;
                    db.Schools.Add(school);
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                return(View(model));
            }
        }
Beispiel #18
0
 public JsonResult AddUserToClass(string selectedUser, string classID)
 {
     using (JournalContext db = new JournalContext())
     {
         var  pupilRole       = Guid.Parse(Roles.Pupil);
         var  newSlectedUser  = Guid.Parse(selectedUser);
         var  selectedClassID = Guid.Parse(classID);
         User user            = db.Users.Find(newSlectedUser);
         user.ClassID = selectedClassID;
         var schoolID = user.SchoolID;
         db.SaveChanges();
         var newListOfUser = db.Users.Where(c => c.UserRollID == pupilRole && c.SchoolID == schoolID && c.ClassID == selectedClassID).Select(x => new SelectListItem()
         {
             Value = x.ID.ToString(), Text = x.FirstName + " " + x.LastName
         }).ToList();
         return(Json(newListOfUser, JsonRequestBehavior.AllowGet));
     }
 }
Beispiel #19
0
 public ActionResult Create(ClassViewModels model)
 {
     using (JournalContext db = new JournalContext())
     {
         model.Schools = db.Schools.Select(school => new SelectListItem()
         {
             Value = school.ID.ToString(), Text = school.ShortName
         }).ToList();
         model.SchoolID = Guid.Parse(model.SelectedSchool);
         if (ModelState.IsValid)
         {
             Class classes = (Class)model;
             classes.ID = Guid.NewGuid();
             db.Classes.Add(classes);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(model));
     }
 }
 public ActionResult CreatePointValue(PointValueViewModel model)
 {
     using (JournalContext db = new JournalContext())
     {
         var identity = (ClaimsIdentity)User.Identity;
         var idString = identity.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier)
                        .Select(c => c.Value).SingleOrDefault();
         Guid id;
         if (Guid.TryParse(idString, out id))
         {
             User user = db.Users.Find(id);
             if (ModelState.IsValid)
             {
                 PointValue pointValue = (PointValue)model;
                 pointValue.ID       = Guid.NewGuid();
                 pointValue.SchoolID = user.SchoolID;
                 db.PointValues.Add(pointValue);
                 db.SaveChanges();
                 return(RedirectToAction("Index"));
             }
         }
         return(View(model));
     }
 }
Beispiel #21
0
 public ActionResult Create(SubjectViewModels model)
 {
     using (JournalContext db = new JournalContext())
     {
         if (ModelState.IsValid)
         {
             var TeacherRoll = Guid.Parse(Roles.Teacher);
             model.Teachers = db.Users.Where(c => c.UserRollID == TeacherRoll).Select(user => new SelectListItem()
             {
                 Value = user.ID.ToString(), Text = user.FirstName + " " + user.LastName
             }).ToList();
             model.SubjectTypes = db.SubjectTypes.Select(subjectType => new SelectListItem()
             {
                 Value = subjectType.ID.ToString(), Text = subjectType.Name
             }).ToList();
             Subject Subject = (Subject)model;
             Subject.ID = Guid.NewGuid();
             db.Subjects.Add(Subject);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(model));
     }
 }
 public ActionResult Edit(SchoolViewModel model)
 {
     using (JournalContext db = new JournalContext())
     {
         if (ModelState.IsValid)
         {
             School school = db.Schools.Find(model.ID);
             school.FullName    = model.FullName;
             school.ShortName   = model.ShortName;
             school.TypeSchool  = model.TypeSchool;
             school.Degree      = model.Degree;
             school.OwnerShip   = model.OwnerShip;
             school.ZipCode     = model.ZipCode;
             school.Address1    = model.Address1;
             school.Address2    = model.Address2;
             school.PhoneNumber = model.PhoneNumber;
             school.Email       = model.Email;
             school.Regulatory  = model.Regulatory;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(model));
     }
 }
Beispiel #23
0
        public ActionResult EditAccount(UserViewModels model)
        {
            using (JournalContext db = new JournalContext())
            {
                if (ModelState.IsValid)
                {
                    User user = db.Users.Find(model.ID);
                    user.FirstName  = model.FirstName;
                    user.LastName   = model.LastName;
                    user.Age        = model.Age;
                    user.Degree     = model.Degree;
                    user.Email      = model.Email;
                    user.Info       = model.Info;
                    user.Phone      = model.Phone;
                    user.ClassID    = model.ClassID;
                    user.Password   = model.Password;
                    user.UserRollID = model.UserRollID;

                    db.SaveChanges();
                    return(RedirectToAction("AccountInfo"));
                }
                return(View(model));
            }
        }
Beispiel #24
0
        private static void AddCountries()
        {
            if (!_context.Countries.Any())
            {
                SwitchIdentity("Countries", true, _isInMemoryDatabase);

                _context.Countries.AddRange(
                    new Country {
                    CountryId = 1, CountryName = "Algeria", CountryCode = "AL", IsEnabled = false
                },
                    new Country {
                    CountryId = 2, CountryName = "Angola", CountryCode = "AN", IsEnabled = false
                },
                    new Country {
                    CountryId = 3, CountryName = "Benin", CountryCode = "BE", IsEnabled = false
                },
                    new Country {
                    CountryId = 4, CountryName = "Botswana", CountryCode = "BO", IsEnabled = false
                },
                    new Country {
                    CountryId = 5, CountryName = "Burkina Faso", CountryCode = "BU", IsEnabled = false
                },
                    new Country {
                    CountryId = 6, CountryName = "Burundi", CountryCode = "BR", IsEnabled = false
                },
                    new Country {
                    CountryId = 7, CountryName = "Cameroon", CountryCode = "CM", IsEnabled = false
                },
                    new Country {
                    CountryId = 8, CountryName = "Cape Verde", CountryCode = "CV", IsEnabled = false
                },
                    new Country {
                    CountryId = 9, CountryName = "Central African Republic", CountryCode = "CR", IsEnabled = false
                },
                    new Country {
                    CountryId = 10, CountryName = "Chad", CountryCode = "CD", IsEnabled = false
                },
                    new Country {
                    CountryId = 11, CountryName = "Comoros", CountryCode = "CO", IsEnabled = false
                },
                    new Country {
                    CountryId = 12, CountryName = "Côte d'Ivoire", CountryCode = "CI", IsEnabled = false
                },
                    new Country {
                    CountryId = 13, CountryName = "Democratic Republic of the Congo", CountryCode = "DC", IsEnabled = false
                },
                    new Country {
                    CountryId = 14, CountryName = "Djibouti", CountryCode = "DJ", IsEnabled = false
                },
                    new Country {
                    CountryId = 15, CountryName = "Egypt", CountryCode = "EG", IsEnabled = false
                },
                    new Country {
                    CountryId = 16, CountryName = "Equatorial Guinea", CountryCode = "EQ", IsEnabled = false
                },
                    new Country {
                    CountryId = 17, CountryName = "Eritrea", CountryCode = "ER", IsEnabled = false
                },
                    new Country {
                    CountryId = 18, CountryName = "Ethiopia", CountryCode = "ET", IsEnabled = false
                },
                    new Country {
                    CountryId = 19, CountryName = "Gabon", CountryCode = "GA", IsEnabled = false
                },
                    new Country {
                    CountryId = 20, CountryName = "Gambia", CountryCode = "GM", IsEnabled = false
                },
                    new Country {
                    CountryId = 21, CountryName = "Ghana", CountryCode = "GH", IsEnabled = false
                },
                    new Country {
                    CountryId = 22, CountryName = "Guinea", CountryCode = "GU", IsEnabled = false
                },
                    new Country {
                    CountryId = 23, CountryName = "Guinea-Bissau", CountryCode = "GI", IsEnabled = false
                },
                    new Country {
                    CountryId = 24, CountryName = "Kenya", CountryCode = "KE", IsEnabled = true
                },
                    new Country {
                    CountryId = 25, CountryName = "Lesotho", CountryCode = "LE", IsEnabled = false
                },
                    new Country {
                    CountryId = 26, CountryName = "Liberia", CountryCode = "LI", IsEnabled = false
                },
                    new Country {
                    CountryId = 27, CountryName = "Libya", CountryCode = "LB", IsEnabled = false
                },
                    new Country {
                    CountryId = 28, CountryName = "Madagascar", CountryCode = "MD", IsEnabled = false
                },
                    new Country {
                    CountryId = 29, CountryName = "Malawi", CountryCode = "ML", IsEnabled = false
                },
                    new Country {
                    CountryId = 30, CountryName = "Mali", CountryCode = "MA", IsEnabled = false
                },
                    new Country {
                    CountryId = 31, CountryName = "Mauritania", CountryCode = "MU", IsEnabled = false
                },
                    new Country {
                    CountryId = 32, CountryName = "Mauritius", CountryCode = "MT", IsEnabled = false
                },
                    new Country {
                    CountryId = 33, CountryName = "Morocco", CountryCode = "MO", IsEnabled = false
                },
                    new Country {
                    CountryId = 34, CountryName = "Mozambique", CountryCode = "MZ", IsEnabled = false
                },
                    new Country {
                    CountryId = 35, CountryName = "Namibia", CountryCode = "NB", IsEnabled = false
                },
                    new Country {
                    CountryId = 36, CountryName = "Niger", CountryCode = "NR", IsEnabled = false
                },
                    new Country {
                    CountryId = 37, CountryName = "Nigeria", CountryCode = "NI", IsEnabled = false
                },
                    new Country {
                    CountryId = 38, CountryName = "Republic of the Congo", CountryCode = "RC", IsEnabled = false
                },
                    new Country {
                    CountryId = 39, CountryName = "Réunion", CountryCode = "RE", IsEnabled = false
                },
                    new Country {
                    CountryId = 40, CountryName = "Rwanda", CountryCode = "RW", IsEnabled = false
                },
                    new Country {
                    CountryId = 41, CountryName = "São Tomé and Príncipe", CountryCode = "ST", IsEnabled = false
                },
                    new Country {
                    CountryId = 42, CountryName = "Senegal", CountryCode = "SE", IsEnabled = false
                },
                    new Country {
                    CountryId = 43, CountryName = "Seychelles", CountryCode = "SY", IsEnabled = false
                },
                    new Country {
                    CountryId = 44, CountryName = "Sierra Leone", CountryCode = "SL", IsEnabled = false
                },
                    new Country {
                    CountryId = 45, CountryName = "Somalia", CountryCode = "SO", IsEnabled = false
                },
                    new Country {
                    CountryId = 46, CountryName = "South Africa", CountryCode = "ZA", IsEnabled = false
                },
                    new Country {
                    CountryId = 47, CountryName = "Sudan", CountryCode = "SU", IsEnabled = false
                },
                    new Country {
                    CountryId = 48, CountryName = "South Sudan", CountryCode = "SS", IsEnabled = false
                },
                    new Country {
                    CountryId = 49, CountryName = "Swaziland", CountryCode = "SZ", IsEnabled = false
                },
                    new Country {
                    CountryId = 50, CountryName = "Tanzania", CountryCode = "TZ", IsEnabled = false
                },
                    new Country {
                    CountryId = 51, CountryName = "Togo", CountryCode = "TG", IsEnabled = false
                },
                    new Country {
                    CountryId = 52, CountryName = "Tunisia", CountryCode = "TU", IsEnabled = false
                },
                    new Country {
                    CountryId = 53, CountryName = "Uganda", CountryCode = "UG", IsEnabled = true
                },
                    new Country {
                    CountryId = 54, CountryName = "Western Sahara", CountryCode = "WS", IsEnabled = false
                },
                    new Country {
                    CountryId = 55, CountryName = "Zambia", CountryCode = "ZA", IsEnabled = false
                },
                    new Country {
                    CountryId = 56, CountryName = "Zimbabwe", CountryCode = "ZI", IsEnabled = false
                },
                    new Country {
                    CountryId = 57, CountryName = "Unknown", CountryCode = "UU", IsEnabled = true
                },
                    new Country {
                    CountryId = 58, CountryName = "United States", CountryCode = "US", IsEnabled = true
                },
                    new Country {
                    CountryId = 59, CountryName = "United Kingdom", CountryCode = "UK", IsEnabled = true
                }
                    );

                _context.SaveChanges();
                SwitchIdentity("Countries", false, _isInMemoryDatabase);
                _logger.LogDebug("Completed Countries table updates with {0} rows.", _context.Countries.Count());
            }
        }
Beispiel #25
0
 public void Commit()
 {
     _context.SaveChanges();
 }
Beispiel #26
0
        public static async Task SeedCoaches(JournalContext context)
        {
            //Seed coaches
            List <Question> shairaQuestions = new List <Question>();

            shairaQuestions.Add(new Question
            {
                Index        = 0,
                QuestionText = "How was your day today?",
                Type         = QuestionType.Text
            });
            shairaQuestions.Add(new Question
            {
                Index        = 1,
                QuestionText = "Were you a good boy/girl?",
                Type         = QuestionType.Text
            });
            shairaQuestions.Add(new Question
            {
                Index        = 2,
                QuestionText = "What did you get done today?",
                Type         = QuestionType.LongText
            });
            shairaQuestions.Add(new Question
            {
                Index        = 3,
                QuestionText = "How many naughty things did you eat?",
                Type         = QuestionType.Numerical
            });
            shairaQuestions.Add(new Question
            {
                Index        = 4,
                QuestionText = "What will be tomorrows most important task?",
                Type         = QuestionType.Text
            });
            shairaQuestions.Add(new Question
            {
                Index        = 5,
                QuestionText = "What are you most grateful for?",
                Type         = QuestionType.LongText
            });

            Coach newCoach = new Coach
            {
                Author       = "Nathan",
                Name         = "Shaira",
                QuestionList = shairaQuestions
            };

            context.Coaches.Add(newCoach);


            List <Question> nathanQuestions = new List <Question>();

            nathanQuestions.Add(new Question
            {
                Index        = 0,
                QuestionText = "What was the highlight of today?",
                Type         = QuestionType.Text
            });
            nathanQuestions.Add(new Question
            {
                Index        = 1,
                QuestionText = "What things do you feel great about?",
                Type         = QuestionType.LongText
            });
            nathanQuestions.Add(new Question
            {
                Index        = 2,
                QuestionText = "What do you feel not-so-great about?",
                Type         = QuestionType.LongText
            });
            nathanQuestions.Add(new Question
            {
                Index        = 3,
                QuestionText = "What did you learn today?",
                Type         = QuestionType.LongText
            });
            nathanQuestions.Add(new Question
            {
                Index        = 4,
                QuestionText = "What will be tomorrows biggest challenge?",
                Type         = QuestionType.Text
            });

            Coach newCoachN = new Coach
            {
                Author       = "Nathan",
                Name         = "Nathan",
                QuestionList = nathanQuestions
            };

            context.Coaches.Add(newCoachN);

            List <Question> jackQuestions = new List <Question>();

            jackQuestions.Add(new Question
            {
                Index        = 0,
                QuestionText = "How was waking up this morning?",
                Type         = QuestionType.LongText
            });
            jackQuestions.Add(new Question
            {
                Index        = 1,
                QuestionText = "What time did you start effectively working?",
                Type         = QuestionType.Text
            });
            jackQuestions.Add(new Question
            {
                Index        = 2,
                QuestionText = "How many hours of work did you get done this morning?",
                Type         = QuestionType.Numerical
            });
            jackQuestions.Add(new Question
            {
                Index        = 3,
                QuestionText = "What is the biggest challenge to your morning routine?",
                Type         = QuestionType.LongText
            });
            jackQuestions.Add(new Question
            {
                Index        = 4,
                QuestionText = "How can this be improved?",
                Type         = QuestionType.LongText
            });

            Coach newCoachJ = new Coach
            {
                Author       = "Nathan",
                Name         = "Jack",
                QuestionList = jackQuestions
            };

            context.Coaches.Add(newCoachJ);

            context.SaveChanges();
        }
Beispiel #27
0
        public void Post([FromBody] List <GcItem> items)
        {
            if (items != null && items.Count > 2)
            {
                UserData user = new UserData
                {
                    Email     = User.Identity.Name,
                    FirstName = User.Identity.Name
                };

                Conversation newConvo = new Conversation
                {
                    UserData = user,
                    DateTime = DateTime.Now
                };

                int    iCoach    = 0;
                int    iUser     = 0;
                string coachName = "";
                newConvo.QuestionsAsked = new List <Question>();
                newConvo.ResponseList   = new List <Response>();

                foreach (GcItem item in items)
                {
                    if (item.compstyle != null && item.compstyle.Contains("coach"))
                    {
                        coachName = item.Author;
                        newConvo.QuestionsAsked.Add(new Question
                        {
                            Index        = iCoach,
                            QuestionText = item.Content
                        });
                        iCoach++;
                    }
                    else
                    {
                        newConvo.ResponseList.Add(new Response
                        {
                            Index          = iUser,
                            IsTextResponse = true,
                            TextResponse   = item.Content
                        });
                        iUser++;
                    }
                }
                String doc = "<p>Journal entry at " + DateTime.Now.ToShortDateString() + " - " + DateTime.Now.ToShortTimeString() + " by " + User.Identity.Name + "</p>";
                foreach (var item in newConvo.QuestionsAsked)
                {
                    doc = doc + "<p><b>" + "(" + (item.Index + 1) + ") " + item.QuestionText + "</b></p>";
                    string response = "-";
                    try
                    {
                        response = newConvo.ResponseList[item.Index].TextResponse;
                    }
                    catch (Exception) { }

                    doc = doc + "<p>" + response + "</p>";
                }
                newConvo.Document = doc;
                //TODO add coach ref
                coachName = coachName.Replace("Coach ", "");
                var coach = _db.Coaches.FirstOrDefault(i => i.Name == coachName);

                newConvo.Coach = coach;

                _db.Conversations.Add(newConvo);
                _db.SaveChanges();
            }
        }