private TheoryResource BuildTheoryResource(TheoryCreate model)
        {
            var entity = new TheoryResource();

            entity.Title          = model.Title;
            entity.Description    = model.Description;
            entity.DateCreated    = DateTimeOffset.Now;
            entity.IsDownloadable = model.IsDownloadable;
            entity.IsPublic       = model.IsPublic;
            entity.TeacherId      = model.TeacherId;
            entity.File           = _fileHelper.BuildResourceFile(model.File);
            entity.Topic          = model.Topic;
            entity.GradeLevel     = model.GradeLevel;

            return(entity);
        }
        public bool CreateTheory(TheoryCreate model)
        {
            var entity =
                new Theory()
            {
                OwnerId     = _userId,
                Subject     = model.Subject,
                Content     = model.Content,
                DateCreated = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Theories.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
 public ActionResult CreateTheory(TheoryCreate model)
 {
     if (this.ModelState.IsValid)
     {
         var service = CreateResourceService();
         if (service.CreateResource(model))
         {
             TempData["SaveResult"] = "Resource was successfully published.";
             return(RedirectToAction("Detail", "Teacher", new { id = this.User.Identity.GetUserId() }));
         }
         else
         {
             TempData["ErrorMessage"] = "Resource could not be added. Try again later.";
             return(RedirectToAction("Detail", "Teacher", new { id = this.User.Identity.GetUserId() }));
         }
     }
     else
     {
         return(View(model));
     }
 }