コード例 #1
0
        public async Task UpdateItemStatus(ItemStats itemStats)
        {
            var student = _studentRepository.GetStudentByRFID(itemStats.StudentRFID);
            var log     = new ItemLog
            {
                dateTime = DateTime.Now
            };
            var item = _itemRepository.GetItemById(itemStats.Id);

            item.IsInBox         = itemStats.IsInBox;
            item.StudentBorrowed = student.FullName;
            item.StudentId       = student.Id;
            if (itemStats.IsInBox)
            {
                if (student != null)
                {
                    log.Message = "Racket No " + item.Id + " Is returned by: " + student.email;
                }
                else
                {
                    log.Message = "Warning! item is returned but with unkown User";
                    //activate warning
                }
            }
            if (!itemStats.IsInBox)
            {
                log.Message = "Racket No " + item.Id + " Is Borrowed by: " + student.FullName;
                await _itemRepository.count();
            }
            _itemRepository.AddLog(log);
            if (item.Id == 1)
            {
                await _boxHub.Clients.All.SendAsync("Item1", item.StudentBorrowed, item.IsInBox, DateTime.Now.ToString("HH:mm:ss"));

                await _notificationsRepository.AddNotificationAsync(log.Message);
            }
            if (item.Id == 2)
            {
                await _boxHub.Clients.All.SendAsync("Item2", item.StudentBorrowed, item.IsInBox, DateTime.Now.ToString("HH:mm:ss"));

                await _notificationsRepository.AddNotificationAsync(log.Message);
            }
            _mail.GenMail(
                student.email, "You borrowed a Racket from pingisBox",
                "You borrowed A racket with id: " + item.RFID + " from pingisBox \nBorrowing time:"
                + DateTime.Now.ToString("HH:mm:ss") + " You should return it letast at"
                + DateTime.Now.AddHours(1).ToString("HH:mm:ss"));
            if (!item.IsInBox)
            {
                BackgroundJob.Schedule(() =>

                                       Reminder(item.Id, student.email, "Reminder From pingisBox",
                                                "You borrowed A racket with id: " + item.RFID + " from pingisBox \nBorrowing time:"
                                                + DateTime.Now.ToString("HH:mm:ss") + "\nPlease return the racket as soon as possible"
                                                ), TimeSpan.FromMinutes(60)


                                       );
            }
        }