public bool CrearCuentaAdministrador(string nombre, string apellido, string usuario, string password, string tipoAdministrador, int IdFacultad) { try { var salt = PassSalt.Create(); var hash = PassHash.Create(password, salt); var administrador = new Administrador() { Nombre = nombre, Apellido = apellido, Usuario = usuario, Passwd = hash, Salt = salt }; _contextoGeneral.Administrador.Add(administrador); _contextoGeneral.SaveChanges(); if (tipoAdministrador == "Facultad") { var tipoAdminFac = new AdministradorFacultad() { FacultadId = IdFacultad, AdministradorId = administrador.Id }; _contextoGeneral.AdministradorFacultad.Add(tipoAdminFac); } else { var tipoAdminUdelar = new AdministradorUdelar() { AdministradorId = administrador.Id }; _contextoGeneral.AdministradorUdelar.Add(tipoAdminUdelar); } _contextoGeneral.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex); return(false); } return(true); }
public void AddAdministrador(Administrador a, string tipo, int idFacultad) { _contextoGeneral.Administrador.Add(a); _contextoGeneral.SaveChanges(); if (tipo == "Facultad") { var af = new AdministradorFacultad() { AdministradorId = a.Id, FacultadId = idFacultad }; _contextoGeneral.AdministradorFacultad.Add(af); _contextoGeneral.SaveChanges(); } else { var au = new AdministradorUdelar() { AdministradorId = a.Id }; _contextoGeneral.AdministradorUdelar.Add(au); _contextoGeneral.SaveChanges(); } }