Beispiel #1
0
        public async Task <ActionResult <Entry> > DeleteEntry(int id, string reason = "test")
        {
            var entry = await _context.Entry.FindAsync(id);



            if (entry == null)
            {
                return(NotFound());
            }

            //deleted entries to garbage
            GarbageEntry garbage = new GarbageEntry();

            garbage             = _mapper.Map <GarbageEntry>(entry);
            garbage.deletedFor  = reason;
            garbage.deletedDate = DateTime.Now;
            _context.GarbageEntry.Add(garbage);

            //entry delete
            _context.Entry.Remove(entry);



            //delete yapılınca başlıktaki updatedate'i tekrar eski tarihe çek yapıldı
            if (_context.Entry.Where(s => (s.subjectId == entry.subjectId))
                .OrderByDescending(e => e.createDate).FirstOrDefault() != null)
            {
                var list = _context.Entry.Where(s => (s.subjectId == entry.subjectId))
                           .OrderByDescending(e => e.createDate).FirstOrDefault();
                var list2 = _context.Subject.Where(s => s.id == entry.subjectId).FirstOrDefault();
                list2.updateDate = list.createDate;
                list2.totalCount = list2.totalCount - 1;
                _context.Subject.Update(list2);
            }
            else
            {
                var subject = await _context.Subject.FindAsync(entry.subjectId);

                _context.Subject.Remove(subject);
            }
            _context.SaveChanges();
            return(entry);
        }
Beispiel #2
0
        public User lastloginupdate(int id)
        {
            var user = _context.User.Find(id);

            user.lastLoginDate         = DateTime.Now;
            _context.Entry(user).State = EntityState.Modified;
            _context.SaveChanges();

            return(user);
        }
        public void SubjectCount()
        {
            var subjectcount = _context.Subject.Select(p => p.id).ToList();

            for (int i = 0; i < subjectcount.Count(); i++)
            {
                var subject    = _context.Subject.Find(subjectcount[i]);
                var totalcount = _context.Entry.Where(p => p.subjectId == subject.id).Count();
                subject.totalCount            = totalcount;
                _context.Entry(subject).State = EntityState.Modified;
            }
            _context.SaveChanges();
        }