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()); } }
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()); } }
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)); } }
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)); } }
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()); } }
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")); } }
// GET: Invidivual public ActionResult Index() { var repository = new IndividualRepository(context); var individuals = repository.GetAll(); var model = MapperHelpers.Map <IEnumerable <IndividualViewModel> >(individuals); return(View(model)); }
// 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)); }
// 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)); }
// 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)); }
// 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)); }
// 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)); }
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)); }
// 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)); }
// 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)); } }
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()); } }
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)); } }