Exemplo n.º 1
0
        public IHttpActionResult GetById(int id)
        {
            var assignment = assignmentRepo.GetById(id);

            if (assignment == null)
            {
                return(Content(HttpStatusCode.NotFound, "Item does not exist"));
            }
            return(Ok(assignment));
        }
        public ActionResult Update(int id)
        {
            var        assignmentRepository = new AssignmentRepository();
            Assignment entity = assignmentRepository.GetById(id);

            return(View(entity));
        }
Exemplo n.º 3
0
        //
        // GET: /Comment/
        public ActionResult Index(int id)
        {
            var commentsRepository = new CommentsRepository();
            var commentsList       = new List <Comment>();

            var commentsFromRepo = commentsRepository.GetAll(comment => comment.AssignmentId == id);

            // var commentsFromRepo = commentsRepository.GetAll();
            //foreach (var comment in commentsFromRepo)
            //{
            //    if (comment.AssignmentId == id)
            //    {
            //        commentsList.Add(comment);
            //    }
            //}
            ViewBag.AssignmentId = id;

            var assignmentRepository = new AssignmentRepository();

            ViewBag.AssignmentTitle = assignmentRepository.GetById(id).Title;

            commentsList.AddRange(commentsFromRepo);

            return(View(commentsList));
        }
        //
        // GET: /Comment/
        public ActionResult Index(int id)
        {
            var commentsRepository = new CommentsRepository();
            var commentsList       = new List <Comment>();

            var commentsFromRepository = commentsRepository
                                         .GetAll(comment => comment.AssignmentId == id);

            //foreach (var comment in commentsFromRepository)
            //{
            //    if (comment.AssignmentId == id)
            //    {
            //        commentsList.Add(comment);
            //    }
            //}

            ViewBag.AssignmentId = id;

            var assignmentRepository = new AssignmentRepository();

            ViewBag.AssignmentTitle =
                assignmentRepository.GetById(id).Title;

            // Navigational Property Demo

            //var firstComment = commentsList.FirstOrDefault();
            //ViewBag.AssignmentTitle = firstComment.Assignment.Title;

            commentsList.AddRange(commentsFromRepository);

            return(View(commentsList));
        }
        public static void AssignmentById(int?id)
        {
            AssignmentRepository assignmentRepository = new AssignmentRepository();

            var assignment = assignmentRepository.GetById(id);

            Console.WriteLine("{0, -5}{1, -10}", assignment.AssignmentId, assignment.Title);
        }
        public ActionResult Delete(int id)
        {
            var        assignmentRepository = new AssignmentRepository();
            Assignment entity = assignmentRepository.GetById(id);

            assignmentRepository.Delete(entity);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 7
0
        public ActionResult Details(int?id)
        {
            AssignmentRepository assignmentRepository = new AssignmentRepository();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var assignment = assignmentRepository.GetById(id);

            if (assignment == null)
            {
                return(HttpNotFound());
            }
            return(View(assignment));
        }
        //
        // GET: /Comment/
        public ActionResult Index(int id)
        {
            var commentsRepository = new CommentsRepository();
            var commentsList       = new List <Comment>();

            var commentsFromRepo = commentsRepository.GetAll(comment => comment.AssignmentId == id);

            // var commentsFromRepo = commentsRepository.GetAll();
            //foreach (var comment in commentsFromRepo)
            //{
            //    if (comment.AssignmentId == id)
            //    {
            //        commentsList.Add(comment);
            //    }
            //}

            commentsList.AddRange(commentsFromRepo);

            var assignmentRepository = new AssignmentRepository();

            var model = new CommentListViewModel();

            model.AssignmentTitle = assignmentRepository.GetById(id).Title;
            model.AssignmentId    = id;

            foreach (var entity in commentsList)
            {
                var commentModel = new CommentViewModel()
                {
                    Id           = entity.Id,
                    AssignmentId = entity.AssignmentId,
                    Content      = entity.Content,
                    CreatedAt    = entity.CreatedAt,
                    UpdatedAt    = entity.UpdatedAt
                };

                model.Comments.Add(commentModel);
            }


            return(View(model));
        }
        //
        // GET: /Comment/
        public ActionResult Index(int id)
        {
            var            commentsRepository = new CommentsRepository();
            List <Comment> comments           = new List <Comment>();

            comments.AddRange(commentsRepository
                              .GetAll(comment => comment.AssignmentId == id));

            var assignmentRepostory = new AssignmentRepository();

            ViewBag.AssignmentTitle = assignmentRepostory.GetById(id).Title;
            ViewBag.AssignmentId    = id;

            // Navigational Properties example

            //var firstEntity = comments.FirstOrDefault();
            //ViewBag.AssignmentTitle =
            //    firstEntity != null ? firstEntity.Assignment.Title : "No COMMENTS YET";

            return(View(comments));
        }
Exemplo n.º 10
0
 public Assignment GetById(int id)
 {
     return(repository.GetById(id));
 }