Пример #1
0
        public async Task count()
        {
            var date   = DateTime.Now.ToString("dd/MM-yy");
            var _count = _appDbCotext.itemCount.Last();

            if (_count.Time != date || _count == null)
            {
                var count = new ItemCount
                {
                    Time          = DateTime.Now.ToString("dd/MM-yy"),
                    TimesBorrowed = 1
                };
                _appDbCotext.itemCount.Add(count);
                await _boxHub.Clients.All.SendAsync("TimesBorrowedToday", count.TimesBorrowed, count.Time, DateTime.Now.ToString("HH:mm:ss"));
            }
            else
            {
                _count.TimesBorrowed = _count.TimesBorrowed + 1;
                await _boxHub.Clients.All.SendAsync("TimesBorrowedToday", _count.TimesBorrowed, _count.Time, DateTime.Now.ToString("HH:mm:ss"));
            }
            await _appDbCotext.SaveChangesAsync();
        }
Пример #2
0
        public async Task <ItemCount> GetCount()
        {
            var date   = DateTime.Now.ToString("dd/MM-yy");
            var _count = _appDbCotext.itemCount.Last();

            if (_count.Time != date || _count == null)
            {
                var count = new ItemCount
                {
                    Time          = DateTime.Now.ToString("dd/MM-yy"),
                    TimesBorrowed = 0
                };
                _appDbCotext.itemCount.Add(count);
                await _appDbCotext.SaveChangesAsync();

                return(count);
            }
            else
            {
                return(_appDbCotext.itemCount.Last());
            }
        }