Пример #1
0
 public User Create(User itemToCreate)
 {
     var user = _context.Users.Add(itemToCreate);
     _context.Entry(user.Role).State = EntityState.Modified;
     _context.SaveChanges();
     return user;
 }
Пример #2
0
 public ActionResult Add(TeacherRegisterModel modelTeacher)
 {
     var teacherModel = Mapper.Map<TeacherRegisterModel, Teacher>(modelTeacher);
     var myTeacher = _teacherRepository.GenerateTeacherFromRegisterModel(teacherModel);
     if (_teacherRepository.ExistIdNumber(modelTeacher.IdNumber))
     {
         _viewMessageLogic.SetNewMessage("Dato Invalido", "Ya existe el numero de Identidad ya existe", ViewMessageType.ErrorMessage);
         return RedirectToAction("Index");
     }
     if (_teacherRepository.ExistEmail(modelTeacher.Email))
     {
         _viewMessageLogic.SetNewMessage("Dato Invalido", "El Correo Electronico ya esta en uso", ViewMessageType.ErrorMessage);
         return RedirectToAction("Index");
     }
     var newUser = new User
     {
         DisplayName = modelTeacher.FirstName,
         Email = modelTeacher.Email,
         Password = modelTeacher.Password,
         IsActive = true,
         Role = Roles.Maestro
     };
     newUser = _userRepository.Create(newUser);
     myTeacher.MyUser = newUser;
     _teacherRepository.Create(myTeacher);
     const string title = "Maestro Agregado";
     var content = "El maestro " + myTeacher.FullName + "ha sido agregado exitosamente.";
     _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage);
     return RedirectToAction("Index");
 }
Пример #3
0
        public ActionResult Add(UserRegisterModel modelUser)
        {
            var myUser = new User
            {
                DisplayName = modelUser.DisplaName,
                Email = modelUser.UserName,
                Password = modelUser.Password,
                IsActive = modelUser.Status,
                Role = Roles.Administrador
            };

            if (_userRepository.ExistEmail(modelUser.UserName))
            {
                _viewMessageLogic.SetNewMessage("Dato Invalido", "El Correo Electronico ya esta en uso", ViewMessageType.ErrorMessage);
                return RedirectToAction("Index");
            }

            var user = _userRepository.Create(myUser);
            const string title = "Usuario Agregado";
            var content = "El usuario " + user.DisplayName + " - " + user.Email + " ha sido agregado exitosamente.";
            _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage);
            return RedirectToAction("Index");
        }
Пример #4
0
 public ActionResult Create(ParentRegisterModel modelParent)
 {
     var parentModel = Mapper.Map<ParentRegisterModel, Parent>(modelParent);
     var myParent = _parentRepository.GenerateParentFromRegisterModel(parentModel);
     if (_parentRepository.ExistIdNumber(modelParent.IdNumber))
     {
         _viewMessageLogic.SetNewMessage("Dato Invalido", "Ya existe el numero de Identidad ya existe", ViewMessageType.ErrorMessage);
         return RedirectToAction("Index");
     }
     if (_parentRepository.ExistEmail(modelParent.Email))
     {
         _viewMessageLogic.SetNewMessage("Dato Invalido", "El Correo Electronico ya esta en uso", ViewMessageType.ErrorMessage);
         return RedirectToAction("Index");
     }
     var newUser = new User
     {
         DisplayName = myParent.FirstName,
         Email = modelParent.Email,
         Password = modelParent.Password,
         IsActive = true,
         Role = Roles.Padre
     };
     newUser = _userRepository.Create(newUser);
     myParent.MyUser = newUser;
      _parentRepository.Create(myParent);
     const string title = "Padre o Tutor Agregado";
     var content = "El Padre o Tutor " + myParent.FullName + " ha sido agregado exitosamente.";
     _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage);
     return RedirectToAction("Index");
 }
Пример #5
0
 public User Update(User itemToUpdate, bool updateRole = true)
 {
     if (updateRole)
         _context.Entry(itemToUpdate.Role).State = EntityState.Modified;
     _context.SaveChanges();
     return itemToUpdate;
 }
Пример #6
0
 private void UpdateSessionFromUser(User user)
 {
     HttpContext.Current.Session[_userEmailIdentifier] = user.Email;
     HttpContext.Current.Session[_userNameIdentifier] = user.DisplayName;
     //HttpContext.Current.Session[_userRoleIdentifier] = user.Role.Name;
     HttpContext.Current.Session[_userIdIdentifier] = user.Id;
 }