public ActionResult Index(string currentFilter, string searchString, int?page) { _viewMessageLogic.SetViewMessageIfExist(); var admins = _peopleWithUserRepository.Filter( x => x.User.IsActive && (x.User.Role.Name.Equals("Administrador") || x.User.Role.Name.Equals("Director"))); if (searchString != null) { page = 1; } else { searchString = currentFilter; } if (!string.IsNullOrWhiteSpace(searchString)) { try { admins = _peopleWithUserRepository.Filter( x => x.User.IsActive && (x.User.Role.Name.Equals("Administrador") || x.User.Role.Name.Equals("Director")) && (x.FullName.Contains(searchString) || x.User.Role.Name.Contains(searchString) || x.IdNumber.Contains(searchString))); } catch (Exception) { admins = _peopleWithUserRepository.Filter( x => x.User.IsActive && (x.User.Role.Name.Equals("Administrador") || x.User.Role.Name.Equals("Director"))); } } ViewBag.CurrentFilter = searchString; var model = Mapper.Map <IEnumerable <PeopleWithUser>, IEnumerable <AdministrativeDisplayModel> >(admins); const int pageSize = 10; var pageNumber = (page ?? 1); return(View(model.ToPagedList(pageNumber, pageSize))); }
public ActionResult Create(TutorRegisterModel modelTutor) { var tutorModel = Mapper.Map <TutorRegisterModel, Tutor>(modelTutor); if (_tutorRepository.Filter(x => x.IdNumber == modelTutor.IdNumber).Any()) { _viewMessageLogic.SetNewMessage("Dato Inválido", "Ya existe un tutor con ese número de Identidad", ViewMessageType.ErrorMessage); return(RedirectToAction("Index")); } if (_peopleWithUserRepository.Filter(x => x.User.Email == modelTutor.Email).Any()) { _viewMessageLogic.SetNewMessage("Dato Inválido", "El Correo Electronico ya esta en uso", ViewMessageType.ErrorMessage); return(RedirectToAction("Index")); } _tutorRepository.Create(tutorModel); var newUser = new User { Name = modelTutor.FirstName, UserOwner = tutorModel, Email = modelTutor.Email, Password = _passwordGenerationService.GenerateTemporaryPassword(), IsUsingDefaultPassword = true, IsActive = true, Role = _roleRepository.Filter(x => x.Name == "Tutor").FirstOrDefault() }; newUser.DefaultPassword = newUser.Password; newUser = _userRepository.Create(newUser); tutorModel.User = newUser; _tutorRepository.Update(tutorModel); const string title = "Tutor Agregado"; var content = "El Tutor " + tutorModel.FullName + " ha sido agregado exitosamente."; _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage); return(RedirectToAction("Create")); }
public ActionResult Edit(TeacherEditModel modelTeacher) { var validImageTypes = new [] { "image/gif", "image/jpeg", "image/pjpeg", "image/png" }; if (modelTeacher.UploadPhoto != null && modelTeacher.UploadPhoto.ContentLength > 0) { if (!validImageTypes.Contains(modelTeacher.UploadPhoto.ContentType)) { ModelState.AddModelError("UploadPhoto", "Por favor seleccione entre una imagen GIF, JPG o PNG"); } } if (ModelState.IsValid) { if ( _peopleWithUserRepository.Filter(x => x.IdNumber.Equals(modelTeacher.IdNumber) && x.Id != modelTeacher.Id && !x.User.Role.Name.Equals("Tutor")) .Any()) { const string title = "Error!"; const string content = "Ya existe un docente o administrativo con ese número de identidad."; _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.ErrorMessage); return(RedirectToAction("Index")); } try { if (modelTeacher.UploadPhoto != null) { using (var binaryReader = new BinaryReader(modelTeacher.UploadPhoto.InputStream)) { modelTeacher.Photo = binaryReader.ReadBytes(modelTeacher.UploadPhoto.ContentLength); } } var myTeacher = _teacherRepository.GetById(modelTeacher.Id); Mapper.Map(modelTeacher, myTeacher); _peopleWithUserRepository.Update(myTeacher); const string title = "Maestro Actualizado"; var content = "El maestro " + myTeacher.FullName + " ha sido actualizado exitosamente."; _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage); return(RedirectToAction("Index")); } catch { var items = ((Gender[])Enum.GetValues(typeof(Gender))).Select(c => new SelectListItem { Text = c.GetEnumDescription(), Value = c.ToString("D") }).ToList(); ViewBag.Genders = new List <SelectListItem>(items); ViewBag.Years = DateTimeController.GetYears(); ViewBag.Months = DateTimeController.GetMonths(); ViewBag.Days = DateTimeController.GetDaysForMonthAndYearStatic(1, DateTime.UtcNow.Year); return(View(modelTeacher)); } } var items2 = ((Gender[])Enum.GetValues(typeof(Gender))).Select(c => new SelectListItem { Text = c.GetEnumDescription(), Value = c.ToString("D") }).ToList(); ViewBag.Genders = new List <SelectListItem>(items2); ViewBag.Years = DateTimeController.GetYears(); ViewBag.Months = DateTimeController.GetMonths(); ViewBag.Days = DateTimeController.GetDaysForMonthAndYearStatic(1, DateTime.UtcNow.Year); return(View(modelTeacher)); }