コード例 #1
0
        public async Task AddAlertsToSchedule(IEnumerable <Alert> alerts, int ScheduleId)
        {
            var schedule = _context.Schedules.Include(x => x.Alerts)
                           .Where(x => x.ScheduleId == ScheduleId).FirstOrDefault();

            if (schedule is null)
            {
                throw new ScheduleDontExistException();
            }
            if (ConsistsOfProperCrons(alerts))
            {
                //manually sets foreign key reference
                foreach (var alert in alerts)
                {
                    alert.ScheduleId = schedule.ScheduleId;
                }
                await _context.Alerts.AddRangeAsync(alerts);
            }
            else
            {
                throw new CroneVerificationException();
            }

            _context.SaveChanges();
        }
コード例 #2
0
        public async Task AddChat(string chatId, string adminId)
        {
            int chatCount = _context.Chats.Where(x => x.ChatId == chatId).Count();

            if (chatCount == 0)
            {
                Chat chat = new Chat
                {
                    AdminId = adminId,
                    ChatId  = chatId
                };
                _context.Chats.Add(chat);

                _context.SaveChanges();
            }
            else
            {
                throw new ChatAlreadyExistsException();
            }
        }