public long GetStudentId(int intId) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { return((from x in context.Student where x.IdAccount == intId select x.IdStudent).First()); } }
public async Task <IActionResult> UpdateProfileTechnician([Bind("IdAccount, Name, Telephone")] Technician technician) { if (GetCurrentUserID() != technician.IdAccount) { return(BadRequest()); } try { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { Technician newTechnician = await context.Technician.SingleOrDefaultAsync(t => t.IdAccount == technician.IdAccount); if (newTechnician == null) { return(NotFound()); } newTechnician.Telephone = technician.Telephone; context.Update(newTechnician); await context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { throw; } return(RedirectToAction("Index")); }
public ProfileViewModel GetAccountModelByID(int intId) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { ProfileViewModel profileViewModel = new ProfileViewModel { }; profileViewModel.Student = context.Student .Include(a => a.IdAccountNavigation) .Include(a => a.IdNationalityNavigation) .Include(a => a.IdCourseNavigation) .FirstOrDefault(s => s.IdAccount == intId); profileViewModel.Technician = context.Technician .Include(a => a.IdAccountNavigation) .FirstOrDefault(s => s.IdAccount == intId); if (profileViewModel.Student != null) { profileViewModel.AccountType = EnumAccountType.STUDENT; return(profileViewModel); } else if (profileViewModel.Technician != null) { profileViewModel.AccountType = EnumAccountType.TECHNICIAN; return(profileViewModel); } return(null); } }
public LoginState IsRegistered(string _strEmail, string _strPassword) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var accountWEmail = from a in context.Account where a.Email == _strEmail select a; var account = accountWEmail.FirstOrDefault(); if (account != null) { var strAccountID = account.IdAccount.ToString(); string strBDPW = ToHex(account.Password, false); if (!strBDPW.Equals(EncryptToMD5(_strPassword))) { return(LoginState.WRONG_PASSWORD); } if (AccountType(strAccountID) == EnumUserType.STUDENT) { return(LoginState.CONNECTED_STUDENT); } else { return(LoginState.CONNECTED_TECH); } } else { return(LoginState.EMAIL_NOTFOUND); } } }
public bool InsertPendingAccount(string strEmail, EnumAccountType enUserType, int intIsAdmin) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { if (context.PendingAccount.Any(p => p.Email == strEmail)) { return(false); } Guid guid = Guid.NewGuid(); PendingAccount pendingAccount = new PendingAccount { Email = strEmail, Guid = guid.ToString(), IsAdmin = Convert.ToBoolean(intIsAdmin) }; context.Add(pendingAccount); context.SaveChanges(); if (enUserType == EnumAccountType.STUDENT) { SendEmailToStudent(strEmail, guid.ToString()); } else { SendEmailToTec(strEmail, guid.ToString()); } return(true); } }
public IActionResult RegisterTechnician([FromQuery] string account_id) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Home")); } ViewData["register-type"] = "technician"; using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { PendingAccount pendingAccount = context.PendingAccount.Where(pa => pa.Guid == account_id).FirstOrDefault(); if (pendingAccount == null) { return(RedirectToAction("Index", "Home")); } else { string strEmail = pendingAccount.Email.ToString(); ViewData["technician-email"] = strEmail; ViewData["technician-isAdmin"] = pendingAccount.IsAdmin; } return(View("Register", new RegisterViewModel { EmailView = ViewData["technician-email"].ToString(), Technician = new Technician { IsAdmin = (bool)ViewData["technician-isAdmin"] } })); } }
public IActionResult RegisterStudent([FromQuery] string account_id) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Home")); } ViewData["register-type"] = "student-register"; List <SelectListItem> lisNationalities = new List <SelectListItem>(); using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var email = context.PendingAccount.Where(pa => pa.Guid == account_id).Select(p => p.Email).FirstOrDefault(); if (email == null) { return(RedirectToAction("Index", "Home")); } else { string strEmail = email.ToString(); string strStudentNumber = email.ToString().Substring(0, 9); ViewData["student-email"] = strEmail; ViewData["student-number"] = strStudentNumber; } } return(View("Register", new RegisterViewModel { Nationalities = PopulateNationalities(), Courses = PopulateCourses() })); }
public bool IsStudent(int intId) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { return(context.Student.Any(t => t.IdAccount == intId)); } }
public bool IsTechnician(int intId) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { return(context.Technician.Any(t => t.IdAccount == intId)); } }
public async void InsertAccount(Account account) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { context.Add(account); await context.SaveChangesAsync(); } }
public async Task <int> GetCurrentStudentECTS(ClaimsPrincipal user) { var intCurrentId = int.Parse(user.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value); using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { return(await context.Student.Where(s => s.IdAccount == intCurrentId).Select(s => s.Credits).SingleOrDefaultAsync()); } }
public string AccountID(string strEmail) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var accoundId = from a in context.Account where a.Email == strEmail select a; return(accoundId.FirstOrDefault().IdAccount.ToString()); } }
public async Task <IActionResult> ShowFiles() { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var files = await context.TestFile.ToListAsync(); return(View(files)); } }
public async Task <FileResult> OpenSignedAppFile(int fileId) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var file = await context.Application.Where(a => a.IdApplication == fileId).Select(a => a.SignedAppFile).SingleOrDefaultAsync(); return(File(file, "application/pdf", "ComprovativoDeCandidatura.pdf")); } }
public string IsAdmin(string _strAccountID) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var isAdmin = ""; isAdmin = (from s in context.Technician where s.IdAccount == Int32.Parse(_strAccountID) select s.IsAdmin).FirstOrDefault().ToString(); return(isAdmin); } }
public async void DeletePendingAccount(string strEmail) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { PendingAccount pendingAccount = await context.PendingAccount.SingleOrDefaultAsync(p => p.Email == strEmail); context.PendingAccount.Remove(pendingAccount); await context.SaveChangesAsync(); } }
private async Task <PaginatedList <PendingAccount> > GetPendingAccountsPaginated(int intPendingPageNumber, int intPendingPageSize) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var pendingAccounts = from s in context.PendingAccount select s; return(await PaginatedList <PendingAccount> .CreateAsync(pendingAccounts.AsNoTracking(), intPendingPageNumber, intPendingPageSize)); } }
public async Task <int> GetNumberPendentApplications(ClaimsPrincipal user) { var intCurrentId = int.Parse(user.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value); using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { return(await context.Application .CountAsync(a => a.IdStudent == GetStudentById(intCurrentId).IdStudent && a.IdState == (from s in context.State where s.Description == "Pendente" select s.IdState).SingleOrDefault())); } }
public async Task <IActionResult> Index() { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var programs = await context.Program .Include(p => p.IdProgramTypeNavigation) .Include(p => p.IdStateNavigation) .ToListAsync(); return(View(programs)); } }
private async void InsertTechnician(Technician technician, string strEmail) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { long lngId = await context.Account.Where(a => a.Email == strEmail).Select(a => a.IdAccount).SingleOrDefaultAsync(); technician.IdAccount = lngId; context.Add(technician); await context.SaveChangesAsync(); } }
private async void ChangePassword(string strEmail, string strPassword) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { Account account = context.Account.SingleOrDefault(a => a.Email == strEmail); if (account != null) { account.Password = StrToArrByte(strPassword); context.Update(account); await context.SaveChangesAsync(); } } }
public EnumUserType AccountType(string _strAccountID) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var student = from s in context.Student where s.IdAccount == Int32.Parse(_strAccountID) select s; var isStudent = student.FirstOrDefault(); if (isStudent != null) { return(EnumUserType.STUDENT); } return(EnumUserType.TECHNICIAN); } }
public async Task <IActionResult> Contact() { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var coordenators = await context.Coordenator .Include(c => c.IdCourseNavigation) .ToListAsync(); var technicians = await context.Technician .Include(t => t.IdAccountNavigation) .ToListAsync(); return(View(new ContactsViewModel { Coordenators = coordenators, Technicians = technicians })); } }
public string AccountName(string _strAccountID) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var name = ""; if (AccountType(_strAccountID) == EnumUserType.STUDENT) { name = (from s in context.Student where s.IdAccount == Int32.Parse(_strAccountID) select s.Name).FirstOrDefault().ToString(); } else { name = (from s in context.Technician where s.IdAccount == Int32.Parse(_strAccountID) select s.Name).FirstOrDefault().ToString(); } return(name); } }
private IEnumerable <SelectListItem> PopulateCourses() { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { List <SelectListItem> lisCourses = new List <SelectListItem>(); var listCourses = context.Course.OrderBy(x => x.Name).ToList(); foreach (Course n in listCourses) { lisCourses.Add(new SelectListItem { Value = n.IdCourse.ToString(), Text = n.Name }); } return(lisCourses); } }
private IEnumerable <SelectListItem> PopulateNationalities() { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { List <SelectListItem> lisNationalities = new List <SelectListItem>(); var listNationalities = context.Nationality.OrderBy(x => x.Description).ToList(); foreach (Nationality n in listNationalities) { lisNationalities.Add(new SelectListItem { Value = n.IdNationality.ToString(), Text = n.Description }); } return(lisNationalities); } }
private async Task <PaginatedList <Technician> > GetTechniciansPaginated(int intTechniciansPageNumber, int intPendingPageSize) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var technicians = (from s in context.Technician select new Technician { Name = s.Name, IdAccountNavigation = new Account { Email = s.IdAccountNavigation.Email }, Telephone = s.Telephone, IsAdmin = s.IsAdmin }); return(await PaginatedList <Technician> .CreateAsync(technicians.AsNoTracking(), intTechniciansPageNumber, intPendingPageSize)); } }
public async Task <IActionResult> MyApplications() { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (User.IsInRole("tecnico") || User.IsInRole("tecnico_admin")) { return(RedirectToAction("Index", "Home")); } AccountController ac = new AccountController(); ProfileController pc = new ProfileController(); int lngCurrentUserId = GetCurrentUserID(); if (!ac.IsStudent(lngCurrentUserId)) { return(RedirectToAction("Index", "Home")); } long studentId = ac.GetStudentId(lngCurrentUserId); using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var lisApplications = await context.Application.Where(a => a.IdStudent == studentId) .Include(a => a.IdStateNavigation) .Include(a => a.IdProgramNavigation) .Include(a => a.ApplicationInstitutions) .ToListAsync(); foreach (Application app in lisApplications) { app.ApplicationInstitutions = await context.ApplicationInstitutions .Include(ai => ai.IdInstitutionNavigation).OrderBy(ai => ai.InstitutionOrder).Where(i => i.IdApplication == app.IdApplication).ToListAsync(); app.IdProgramNavigation.IdProgramTypeNavigation = await context.ProgramType.Where(p => p.IdProgramType == app.IdProgramNavigation.IdProgramType).SingleOrDefaultAsync(); } return(View(lisApplications)); } }
public async Task <IActionResult> Details(string programID) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var program = await context.Program .Include(p => p.IdProgramTypeNavigation) .Include(p => p.IdStateNavigation) .Include(p => p.InstitutionProgram) .FirstOrDefaultAsync(p => p.IdProgram == Int32.Parse(programID)); foreach (var ip in program.InstitutionProgram) { ip.IdOutgoingInstitutionNavigation = await context.Institution .Include(i => i.IdNationalityNavigation) .SingleOrDefaultAsync(i => i.IdInstitution == ip.IdOutgoingInstitution); } return(View(program)); } }
public async Task <IActionResult> FileTest([Bind("File")] FileViewModel viewModel) { using (var context = new CIMOB_IPS_DBContext(new DbContextOptions <CIMOB_IPS_DBContext>())) { var testFile = new TestFile { }; using (var memoryStream = new MemoryStream()) { await viewModel.File.CopyToAsync(memoryStream); testFile.FileTest = memoryStream.ToArray(); } context.Add(testFile); await context.SaveChangesAsync(); } return(RedirectToAction("ShowFiles", "Application")); }