Example #1
0
        private void DebuggingSeeder()
        {
            var generTeacher = new Teacher
            {
                Address   = "Jardines del Valle, 4 calle, 1 etapa",
                BirthDate = new DateTime(1993, 3, 8),
                City      = "San Pedro Sula",
                IsActive  = true,
                FirstName = "Alejandro",
                LastName  = "Diaz",
                FullName  = "Alejandro Diaz",
                IdNumber  = "0501-1993-08405",
                MyGender  = Gender.Masculino,
                State     = "Cortes",
            };

            generTeacher = _teacherRepository.Create(generTeacher);
            var genericTeacher = new User
            {
                UserOwner = generTeacher,
                Email     = "*****@*****.**",
                Password  = "******",
                IsActive  = true,
                Name      = "Alejandro Diaz",
                Role      = _roleRepository.Filter(x => x.Name == "Maestro").FirstOrDefault(),
                IsUsingDefaultPassword = false
            };

            genericTeacher    = _userRepository.Create(genericTeacher);
            generTeacher.User = genericTeacher;
            _teacherRepository.Update(generTeacher);



            var generTutor = new Tutor
            {
                IdNumber  = "0501-1956-03145",
                FirstName = "Erick",
                LastName  = "Caballero",
                FullName  = "Erick Caballero",
                IsActive  = true,
                MyGender  = Gender.Femenino,
                BirthDate = new DateTime(1956, 11, 23),
                Parentage = Parentage.Mother,
                City      = "San Pedro Sula",
                State     = "Cortes",
                Address   = "Jardines del Valle, 4 Calle, 1 Etapa, #9D",
            };

            generTutor = _tutorRepository.Create(generTutor);
            var genericTutor = new User
            {
                UserOwner = generTutor,
                Email     = "*****@*****.**",
                Password  = "******",
                IsActive  = true,
                Name      = "Erick",
                Role      = _roleRepository.Filter(x => x.Name == "Tutor").FirstOrDefault()
            };

            genericTutor    = _userRepository.Create(genericTutor);
            generTutor.User = genericTutor;
            _tutorRepository.Update(generTutor);

            var director = new PeopleWithUser
            {
                Address   = "",
                BirthDate = DateTime.UtcNow,
                City      = "",
                FirstName = "Director Generico",
                IsActive  = true,
                IdNumber  = "0000-0000-00000",
                LastName  = "",
                MyGender  = Gender.Masculino,
                Photo     = null,
                State     = "",
            };

            director.FullName = director.FirstName + "" + director.LastName;
            director          = _peopleWithUserRepository.Create(director);
            var dir = new User
            {
                Email     = "*****@*****.**",
                Password  = "******",
                IsActive  = true,
                UserOwner = director,
                Role      = _roleRepository.Filter(x => x.Name == "Director").FirstOrDefault()
            };

            dir           = _userRepository.Create(dir);
            director.User = dir;
            _peopleWithUserRepository.Update(director);
        }
Example #2
0
        protected override void Seed(MhotivoContext context)
        {
            if (context.Users.Any())
            {
                return;
            }
            _roleRepository           = new RoleRepository(context);
            _userRepository           = new UserRepository(context);
            _teacherRepository        = new TeacherRepository(context);
            _tutorRepository          = new TutorRepository(context);
            _peopleWithUserRepository = new PeopleWithUserRepository(context);
            _privilegeRepository      = new PrivilegeRepository(context);

            var allRoles = new List <Role>();

            var tRole = _roleRepository.Create(new Role {
                Name = "Administrador", Id = 0
            });

            _privilegeRepository.Create(new Privilege {
                Id = 0, Description = "Privilegio de nivel Administrador", Name = "Administrador", Roles = new List <Role> {
                    tRole
                }
            });
            allRoles.Add(tRole);

            tRole = _roleRepository.Create(new Role {
                Name = "Tutor", Id = 1
            });
            _privilegeRepository.Create(new Privilege {
                Id = 1, Description = "Privilegio de nivel Padre", Name = "Padre", Roles = new List <Role> {
                    tRole
                }
            });
            allRoles.Add(tRole);

            tRole = _roleRepository.Create(new Role {
                Name = "Maestro", Id = 2
            });
            _privilegeRepository.Create(new Privilege {
                Id = 1, Description = "Privilegio de nivel Maestro", Name = "Maestro", Roles = new List <Role> {
                    tRole
                }
            });
            allRoles.Add(tRole);

            tRole = _roleRepository.Create(new Role {
                Name = "Director", Id = 3
            });
            _privilegeRepository.Create(new Privilege {
                Id = 1, Description = "Privilegio de nivel Director", Name = "Director", Roles = new List <Role> {
                    tRole
                }
            });
            allRoles.Add(tRole);

            _privilegeRepository.Create(new Privilege {
                Id = 1, Description = "Privilegio de Login", Name = "Login", Roles = allRoles
            });

            var adminPeople = new PeopleWithUser
            {
                Address   = "",
                BirthDate = DateTime.UtcNow,
                City      = "",
                FirstName = "Rectora",
                IsActive  = true,
                IdNumber  = "0000-0000-00000",
                LastName  = "",
                MyGender  = Gender.Masculino,
                Photo     = null,
                State     = ""
            };

            adminPeople.FullName = adminPeople.FirstName + "" + adminPeople.LastName;
            adminPeople          = _peopleWithUserRepository.Create(adminPeople);
            var admin = new User
            {
                Email     = "*****@*****.**",
                Password  = "******",
                IsActive  = true,
                UserOwner = adminPeople,
                Role      = _roleRepository.Filter(x => x.Name == "Administrador").FirstOrDefault()
            };

            admin            = _userRepository.Create(admin);
            adminPeople.User = admin;
            _peopleWithUserRepository.Update(adminPeople);
            DebuggingSeeder(); //MAKE SURE TO COMMENT THIS LINE BEFORE DEPLOYING.
        }
Example #3
0
        public ActionResult Edit(AdministrativeEditModel modelAdmin)
        {
            var validImageTypes = new []
            {
                "image/gif",
                "image/jpeg",
                "image/pjpeg",
                "image/png"
            };

            if (modelAdmin.UploadPhoto != null && modelAdmin.UploadPhoto.ContentLength > 0)
            {
                if (!validImageTypes.Contains(modelAdmin.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(modelAdmin.IdNumber) && x.Id != modelAdmin.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 (modelAdmin.UploadPhoto != null)
                    {
                        using (var binaryReader = new BinaryReader(modelAdmin.UploadPhoto.InputStream))
                        {
                            modelAdmin.Photo = binaryReader.ReadBytes(modelAdmin.UploadPhoto.ContentLength);
                        }
                    }
                    var myAdmin = _peopleWithUserRepository.GetById(modelAdmin.Id);
                    Mapper.Map(modelAdmin, myAdmin);
                    _peopleWithUserRepository.Update(myAdmin);
                    const string title   = "Administrativo Actualizado";
                    var          content = "El administrativo " + myAdmin.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(modelAdmin));
                }
            }
            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(modelAdmin));
        }