예제 #1
0
        public async Task <IActionResult> YoklamaGelenler(int yokId)
        {
            AcilanDers yoklama = await _context.AcilanDersler.Include(x => x.Ders).FirstOrDefaultAsync(x => x.Id == yokId);

            if (yoklama == null)
            {
                return(BadRequest());
            }

            if (yoklama.Ders.OgretmenId != ActiveUserId)
            {
                return(BadRequest());
            }

            List <int>     ogrIds          = (await _context.AlinanDersler.Where(x => x.DersId == yoklama.Ders.Id).ToListAsync()).Select(x => x.OgrenciId).ToList();
            List <AppUser> dersOgrencileri = await _context.Users.Where(x => ogrIds.Contains(x.Id)).Include(x => x.OgrenciDetay).ToListAsync();

            List <int> yoklananIdler = (await _context.YoklananOgrenciler.Where(x => x.DersId == yoklama.DersId && x.Key == yoklama.Key).ToListAsync()).Select(x => x.OgrenciId).ToList();


            List <DersYoklamaBilgisi> dersYoklamaBilgisi = new List <DersYoklamaBilgisi>();

            foreach (AppUser appUser in dersOgrencileri)
            {
                dersYoklamaBilgisi.Add(new DersYoklamaBilgisi()
                {
                    Ogrenci = appUser, Yoklandi = yoklananIdler.Contains(appUser.Id)
                });
            }

            return(Json(dersYoklamaBilgisi));
        }
예제 #2
0
        public async Task <IActionResult> YoklamaAc(int DersId, int Dakika)
        {
            List <int> dersIdler = (await _context.Dersler.Where(x => x.OgretmenId == ActiveUserId).ToListAsync()).Select(x => x.Id).ToList();
            AcilanDers ders      = await _context.AcilanDersler.Where(x => x.DersId == DersId && dersIdler.Contains(x.DersId) && x.SonGecerlilik >= DateTime.Now).FirstOrDefaultAsync();


            Dakika = Math.Abs(Dakika);

            if (ders != null)
            {
                ders.SonGecerlilik.AddMinutes(Dakika);
                _context.Update(ders);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Yoklama), new { id = ders.Id }));
            }

            AcilanDers yoklama = new AcilanDers()
            {
                DersId        = DersId,
                SonGecerlilik = DateTime.Now.AddMinutes(Dakika),
                Key           = Guid.NewGuid().ToString()
            };

            _context.AcilanDersler.Add(yoklama);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Yoklama), new { id = yoklama.Id }));
        }
예제 #3
0
        public async Task <ActionResult> BeniYokla(string Key)
        {
            var     email = User.Claims.First().Value;
            AppUser user  = await _userManager.FindByEmailAsync(email);

            List <int> ogrenciDersleri = (await _context.AlinanDersler.Where(x => x.OgrenciId == user.Id)
                                          .Include(x => x.Ders)
                                          .ToListAsync()).Select(x => x.Ders).Select(x => x.Id).ToList();
            DateTime   now  = DateTime.Now;
            AcilanDers ders = await _context.AcilanDersler.Where(x => x.Key == Key && x.SonGecerlilik >= now && ogrenciDersleri.Contains(x.DersId)).FirstOrDefaultAsync();

            if (ders == null)
            {
                return(BadRequest());
            }


            if (await _context.YoklananOgrenciler.FirstOrDefaultAsync(x => x.OgrenciId == user.Id && x.Key == Key) != null)
            {
                return(Ok());
            }

            YoklananOgrenci yoklananOgrenci = new YoklananOgrenci()
            {
                DersId    = ders.DersId,
                OgrenciId = user.Id,
                Key       = Key
            };

            _context.YoklananOgrenciler.Add(yoklananOgrenci);
            await _context.SaveChangesAsync();

            return(Ok());
        }
예제 #4
0
        public async Task <IActionResult> OgrenciEkleCikar(int yoklama, int ogr_id, int ekle)
        {
            if (yoklama <= 0 || ogr_id <= 0 || ekle < 0 || ekle > 1)
            {
                return(RedirectToAction("Index", "Home"));
            }

            AcilanDers ders = await _context.AcilanDersler.Include(x => x.Ders).FirstOrDefaultAsync(x => x.Id == yoklama);

            if (ders == null || ders.Ders.OgretmenId != ActiveUserId)
            {
                return(RedirectToAction("Index"));
            }

            AppUser ogrenci = await _context.Users.Include(x => x.AlinanDersler).Where(x => x.Id == ogr_id).FirstOrDefaultAsync();

            List <int> dersIds = ogrenci.AlinanDersler.Select(x => x.DersId).ToList();

            if (ogrenci == null || !dersIds.Contains(ders.DersId))
            {
                return(RedirectToAction("Index"));
            }

            YoklananOgrenci yoklanma = await _context.YoklananOgrenciler.FirstOrDefaultAsync(x => x.OgrenciId == ogr_id && x.Id == yoklama);

            if (yoklanma == null && ekle == 1)
            {
                // Öğrenci yoklamaya eklenecek
                YoklananOgrenci yeni = new YoklananOgrenci()
                {
                    DersId    = ders.DersId,
                    Key       = ders.Key,
                    OgrenciId = ogrenci.Id
                };

                _context.YoklananOgrenciler.Add(yeni);
                await _context.SaveChangesAsync();
            }
            else if (yoklanma != null && ekle == 0)
            {
                // Öğrenci yoklamadan çıkarılacak
                _context.YoklananOgrenciler.Remove(yoklanma);
                await _context.SaveChangesAsync();
            }


            return(RedirectToAction(nameof(Yoklama), new { id = yoklama }));
        }
예제 #5
0
        public async Task <IActionResult> Yoklama(int id)
        {
            List <int> dersIdler = await _context.Dersler.Where(x => x.OgretmenId == ActiveUserId).Select(x => x.Id).ToListAsync();

            DateTime   date = DateTime.Now;
            AcilanDers ders = await _context.AcilanDersler.Where(x => x.Id == id && dersIdler.Contains(x.DersId))
                              .Include(x => x.Ders)
                              .FirstOrDefaultAsync();

            if (ders == null)
            {
                return(RedirectToAction(nameof(Index)));
            }


            return(View(ders));
        }