Example #1
0
        public BaseViewModel CreateViewModel(IPublishedContent content)
        {
            var viewModel = new CodeSnippetViewModel
            {
                Language = content.GetPropertyValue <string>("languagePicker"),
                Code     = content.GetPropertyValue <string>("code")
            };

            return(viewModel);
        }
Example #2
0
        public async Task <IActionResult> CreateCodeSnippet(int id, CodeSnippetViewModel model)
        {
            var folderId = Int32.Parse(Request.Form["folder"]);

            ViewBag.Categories = _categoryRepo.Categories;
            if (ModelState.IsValid)
            {
                //create new code snippet in CodeSnippet table
                CodeSnippet newCodeSnip = new CodeSnippet();


                newCodeSnip.Name        = model.Name;
                newCodeSnip.Description = model.Description;

                newCodeSnip.Code = model.Code;

                newCodeSnip.Answer = model.Answer;

                _context.CodeSnippets.Add(newCodeSnip);
                await _context.SaveChangesAsync();

                //save changes ^^^

                //create new post and pass in the newly saved code snippet id in as the foreign key

                Post newPost = new Post();


                newPost.CourseId = _courseId;

                newPost.PostCategory = 2;
                newPost.AssignmentId = newCodeSnip.CodeSnippetId;
                newPost.FolderId     = folderId;

                _context.Posts.Add(newPost);

                //everytime we add a post to a folder we update the edit time of the edit col in folder
                var folderToUpdate = _context.Folders.Where(f => f.FolderId == folderId && f.CourseId == id).First();
                folderToUpdate.WhenEdited = DateTime.Now;

                await _context.SaveChangesAsync();

                //to be used for views to show activity of Curse
                UpdateCourse(id);

                TempData["Success"] = "Assignment Successfully Created!";
                return(RedirectToRoute(new
                {
                    controller = "Course",
                    action = "Show",
                    id = _courseId
                }));
            }
            return(View(model));
        }