public ActionResult EditAssignment(int id, EditAssignmentCoursesViewModel model)
        {
            var repository = new AssignedCourseRepository(context);

            try
            {
                if (ModelState.IsValid)
                {
                    var entityForUpd = MapperHelper.Map <AssignedCourse>(model);
                    repository.Update(entityForUpd);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                var includes = new Expression <Func <AssignedCourse, object> >[] { x => x.Course, x => x.Individual };
                var entity   = repository.QueryIncluding(x => x.Id == id, includes, "AssignmentDate").SingleOrDefault();
                model.Course     = MapperHelper.Map <CourseViewModel>(entity.Course);
                model.Individual = MapperHelper.Map <IndividualViewModel>(entity.Individual);
                return(View(model));
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = ex.Message;
                return(View(model));
            }
        }
        public ActionResult Edit(int id, EditAssignmentViewModel model)
        {
            var repository = new AssignedCourseRepository(context);

            try
            {
                if (ModelState.IsValid)
                {
                    var assignmentUpd = MapperHelper.Map <AssignedCourse>(model);
                    repository.Update(assignmentUpd);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(model));
                }
            }
            catch (Exception ex) {
                ViewBag.ErrorMessage = ex.Message;
                return(View(model));
            }

            return(View());
        }
        public ActionResult Create(NewAssignmentViewModel model)
        {
            var repository = new AssignedCourseRepository(context);

            try
            {
                if (ModelState.IsValid)
                {
                    var assignedCourse = MapperHelper.Map <AssignedCourse>(model);
                    assignedCourse.isCompleted = false;
                    repository.Insert(assignedCourse);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                model.CoursesList    = PopulateCourses(model.CourseId);
                model.IndividualList = PopulateInviduals(model.IndividualId);
                return(View(model));
            }
            catch (Exception ex)
            {
                model.CoursesList    = PopulateCourses(model.CourseId);
                model.IndividualList = PopulateInviduals(model.IndividualId);
                return(View(model));
            }
        }
        // GET: Assignment
        public ActionResult Index() //Busqueda
        {
            var repository = new AssignedCourseRepository(context);
            var includes   = new Expression <Func <AssignedCourse, object> >[] { x => x.Course, x => x.Invidivual };
            var courses    = repository.QueryIncluding(null, includes, "AssignmentDate");
            var models     = MapperHelper.Map <ICollection <AssignmentViewModel> >(courses);

            return(View(models));
        }
        public ActionResult NewAssignment()
        {
            var repository = new AssignedCourseRepository(context);
            var model      = new NewAssignmentCoursesViewModel();

            model.CoursesList    = PopulateCourses(model.CourseId);
            model.IndividualList = PopulateIndividuals(model.IndividualId);
            model.AssignmentDate = DateTime.Now;
            return(View(model));
        }
        public ActionResult Edit(int id)
        {
            var repository = new AssignedCourseRepository(context);
            //Expression<>[]
            //Expression<Func<Type,object>>[]{ x=>x.Propiedad }
            var includes = new Expression <Func <AssignedCourse, object> >[] { x => x.Course, x => x.Invidivual };
            var criteria = new AssignedCourse {
                Id = id
            };
            var courses = repository.QueryByExampleIncludig(criteria, includes).SingleOrDefault();
            var model   = MapperHelper.Map <EditAssignmentViewModel>(courses);

            return(View(model));
        }
Beispiel #7
0
        private object m_CargaModeloEdit(int id)
        {
            var repository = new AssignedCourseRepository(context);
            //Expression<>[]
            //Expression<Func<Type,object>>[]{ x=>x.Propiedad }
            var includes = new Expression <Func <AssignedCourse, object> >[] { x => x.Course, x => x.Individual };
            var criteria = new AssignedCourse {
                Id = id
            };
            var courses = repository.QueryByExampleIncludig(criteria, includes).SingleOrDefault();
            var model   = MapperHelper.Map <EditAssignedCourseViewModels>(courses);

            return(model);
        }
Beispiel #8
0
        // GET: Assignment
        public ActionResult Index() //Lista de cursos (busqueda)
        {
            var repository = new AssignedCourseRepository(context);
            //Expression<>[]
            //Expression<Func<Type, bject>>[]{x=><x.propiedad}
            var includes = new Expression <Func <AssignedCourse, object> >[]
            {
                x => x.Course, x => x.Individual
            };
            var courses = repository.QueryIncluding(null, includes, "AssignmentDate");
            var models  = MapperHelper.Map <ICollection <AssignmentViewModel> >(courses);

            return(View(models));
        }
        public ActionResult EditAssignment(int id)
        {
            var repository = new AssignedCourseRepository(context);
            var model      = new EditAssignmentCoursesViewModel();

            try
            {
                var includes = new Expression <Func <AssignedCourse, object> >[] { x => x.Course, x => x.Individual };
                var entity   = repository.QueryIncluding(x => x.Id == id, includes, "AssignmentDate").SingleOrDefault();
                model = MapperHelper.Map <EditAssignmentCoursesViewModel>(entity);
                return(View(model));
            }
            catch (Exception ex) {
                ViewBag.ErrorMessage = ex.Message;
                return(View(model));
            }
        }
        public ActionResult Index(string search)
        {
            var repository = new AssignedCourseRepository(context);
            var includes   = new Expression <Func <AssignedCourse, object> >[] { x => x.Course, x => x.Individual };
            ICollection <AssignedCourse> etities = new List <AssignedCourse>();

            if (string.IsNullOrEmpty(search))
            {
                etities = repository.QueryIncluding(null, includes, "AssignmentDate");
            }
            else
            {
                etities = repository.QueryIncluding(x => x.Individual.Name.Contains(search), includes, "AssignmentDate");
            }
            ViewBag.search = search;
            var model = MapperHelper.Map <ICollection <AssignedCourseItem> >(etities);

            return(View(model));
        }
        public ActionResult NewAssignment(NewAssignmentCoursesViewModel model)
        {
            var repository = new AssignedCourseRepository(context);

            try {
                if (ModelState.IsValid)
                {
                    var entity = MapperHelper.Map <AssignedCourse>(model);
                    entity.IsCompleted = false;
                    repository.Insert(entity);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                model.CoursesList    = PopulateCourses(model.CourseId);
                model.IndividualList = PopulateIndividuals(model.IndividualId);
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = ex.Message;
                return(View(model));
            }
            return(View(model));
        }