Example #1
0
        public ActionResult Edit(int id, EditIndividualViewModel model)
        {
            try
            {
                var repo = new IndividualRepository(context);

                if (model.Email != model.EmailAnterior)
                {
                    var existeEmail = repo.Query(x => x.Email == model.Email && x.Id != model.Id).Count() > 0;
                    if (existeEmail)
                    {
                        ModelState.AddModelError("Email", "El email está ocupado");
                        return(View());
                    }
                }
                else
                {
                    ModelState.Remove("Email");
                }

                // TODO: Add update logic here
                if (ModelState.IsValid)
                {
                    var individual = MapperHelpers.Map <Individual>(model);
                    repo.Update(individual);
                    context.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #2
0
        public ActionResult Create(NewIndividualViewModel model)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    var repo = new IndividualRepository(context);

                    var individualQry = new Individual {
                        Email = model.Email
                    };
                    var emailExiste = repo.QueryByExample(individualQry).Count > 0;
                    if (!emailExiste)
                    {
                        var individual = MapperHelpers.Map <Individual>(model);
                        repo.Insert(individual);

                        context.SaveChanges();
                    }
                    else
                    {
                        ModelState.AddModelError("Email", "El Email está ocupado");
                        return(View(model));
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #3
0
        public ActionResult Create(NewAssignmentsViewModel model)
        {
            try
            {
                var repository = new AssignedRepository(context);

                if (ModelState.IsValid)
                {
                    var assignedCourse = MapperHelpers.Map <AssignedCourse>(model);

                    var individual = MapperHelpers.Map <Individual>(model);

                    assignedCourse.IsCompleted = false;
                    repository.Insert(assignedCourse);
                    context.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                model.CourseList     = PopulateCourses(model.CourseId);
                model.IndividualList = PopulateIndividuals(model.IndividualId);
                return(View(model));
            }
            catch (Exception ex)
            {
                model.CourseList     = PopulateCourses(model.CourseId);
                model.IndividualList = PopulateIndividuals(model.IndividualId);
                return(View(model));
            }
        }
Example #4
0
        public ActionResult Edit(int id, CourseViewModel model)
        {
            var topicRepository = new TopicRepository(context);

            try
            {
                // TODO: Add update logic here
                var repository = new CourseRepository(context);
                if (ModelState.IsValid)
                {
                    var course = MapperHelpers.Map <Course>(model);
                    repository.UpdateCourseWithTopic(course, model.SelectedTopics);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                var topics = topicRepository.Query(null, "Name");
                model.AvailableTopics = MapperHelpers.Map <ICollection <TopicViewModel> >(topics);
                return(View(model));
            }
            catch (Exception ex)
            {
                var topics = topicRepository.Query(null, "Name");
                model.AvailableTopics = MapperHelpers.Map <ICollection <TopicViewModel> >(topics);
                return(View(model));
            }
        }
Example #5
0
 public ActionResult Create(CourseViewModel model)
 {
     try
     {
         var repository = new CourseRepository(context);
         // TODO: Add insert logic here
         if (ModelState.IsValid)
         {
             var courses = MapperHelpers.Map <Course>(model);
             repository.InsertCourseWithTopic(courses, model.SelectedTopics);
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             var topicRepository = new TopicRepository(context);
             var topics          = topicRepository.Query(null, "Name DESC");
             model.AvailableTopics = MapperHelpers.Map <ICollection <TopicViewModel> >(topics);
             return(View(model));
         }
     }
     catch
     {
         return(View());
     }
 }
Example #6
0
        public ActionResult Details(int id)
        {
            try
            {
                var repo           = new IndividualRepository(context);
                var repoAssignment = new AssignedRepository(context);
                var repoCursos     = new CourseRepository(context);

                var individual  = repo.Find(id);
                var indi        = MapperHelpers.Map <IndividualViewModel>(individual);
                var assginments = repoAssignment.Query(x => x.IndividualId == individual.Id).OrderByDescending(x => x.AssingmentDate).ToList();

                foreach (var item in assginments)
                {
                    var course      = repoCursos.Query(x => x.Id == item.CourseId).ToList();
                    var courseModel = MapperHelpers.Map <ICollection <CoursesViewModel> >(course).SingleOrDefault();
                    indi.Courses.Add(courseModel);
                }

                return(View(indi));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index"));
            }
        }
Example #7
0
        // GET: Invidivual
        public ActionResult Index()
        {
            var repository  = new IndividualRepository(context);
            var individuals = repository.GetAll();
            var model       = MapperHelpers.Map <IEnumerable <IndividualViewModel> >(individuals);

            return(View(model));
        }
Example #8
0
        // GET: Course
        public ActionResult Index()
        {
            var repository = new CourseRepository(context);
            var courses    = repository.Query(null, "Name");
            var model      = MapperHelpers.Map <IEnumerable <CourseViewModel> >(courses);

            return(View(model));
        }
Example #9
0
        // GET: Invidivual/Edit/5
        public ActionResult Edit(int id)
        {
            var repo       = new IndividualRepository(context);
            var model      = repo.Find(id);
            var individual = MapperHelpers.Map <EditIndividualViewModel>(model);

            return(View(individual));
        }
Example #10
0
        // GET: Course/Create
        public ActionResult Create()
        {
            var model           = new CourseViewModel();
            var topicRepository = new TopicRepository(context);
            var topics          = topicRepository.Query(null, "Name DESC");

            model.AvailableTopics = MapperHelpers.Map <ICollection <TopicViewModel> >(topics);
            return(View(model));
        }
Example #11
0
        // GET: Course/Details/5
        public ActionResult Details(int id)
        {
            var repository = new CourseRepository(context);
            var includes   = new Expression <Func <Course, object> >[] { x => x.Topics };
            var courses    = repository.QueryIncluding(x => x.Id == id, includes).SingleOrDefault();
            var models     = MapperHelpers.Map <DetailsCourseViewModel>(courses);

            return(View(models));
        }
Example #12
0
        // GET: Course/Delete/5
        public ActionResult Delete(int id)
        {
            var repository = new CourseRepository(context);

            var cursos = repository.Find(id);
            var model  = MapperHelpers.Map <CourseViewModel>(cursos);

            return(View(model));
        }
Example #13
0
        public ActionResult Edit(int id)
        {
            var repository = new AssignedRepository(context);
            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   = MapperHelpers.Map <EditAssignmentViewModel>(courses);

            return(View(model));
        }
Example #14
0
        // GET: Course/Edit/5
        public ActionResult Edit(int id)
        {
            var repository = new CourseRepository(context);
            var repoTopics = new TopicRepository(context);

            var includes = new Expression <Func <Course, object> >[] { x => x.Topics };
            var courses  = repository.QueryIncluding(x => x.Id == id, includes).SingleOrDefault();
            var models   = MapperHelpers.Map <CourseViewModel>(courses);
            var topics   = repoTopics.Query(null, "Name");

            models.AvailableTopics = MapperHelpers.Map <ICollection <TopicViewModel> >(topics);
            models.SelectedTopics  = courses.Topics.Select(x => x.Id.Value).ToArray();
            return(View(models));
        }
Example #15
0
        // GET: Assignment
        public ActionResult Index(string searchTerm = null, string tipo = null)
        {
            var repository = new AssignedRepository(context);
            var includes   = new Expression <Func <AssignedCourse, object> >[] { x => x.Course, x => x.Individual };

            if (tipo == "Persona")
            {
                var courses = repository.QueryIncluding(null, includes, "AssingmentDate").Where(a => searchTerm == null || a.Individual.Name.StartsWith(searchTerm));
                var model   = MapperHelpers.Map <ICollection <AssignmentViewModel> >(courses);
                return(View(model));
            }
            else
            {
                var courses = repository.QueryIncluding(null, includes, "AssingmentDate").Where(a => searchTerm == null || a.Course.Name.StartsWith(searchTerm));
                var model   = MapperHelpers.Map <ICollection <AssignmentViewModel> >(courses);
                return(View(model));
            }
        }
Example #16
0
        public ActionResult Delete(int id, IndividualViewModel model)
        {
            try
            {
                var repo = new IndividualRepository(context);
                //if (ModelState.IsValid)
                //{
                var individual = MapperHelpers.Map <Individual>(model);
                repo.Delete(individual);
                context.SaveChanges();
                //}
                // TODO: Add delete logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #17
0
 public ActionResult Edit(int id, EditAssignmentViewModel model)
 {
     try
     {
         var repository = new AssignedRepository(context);
         if (ModelState.IsValid)
         {
             var update = MapperHelpers.Map <AssignedCourse>(model);
             repository.Update(update);
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             return(HttpNotFound());
         }
     }
     catch (Exception ex)
     {
         ViewBag.MessageError = ex.Message;
         return(View(model));
     }
 }