public static async Task InitialDb() { var db = new MaskContext(); if (db.MedicalMasks.FirstOrDefault() == null) { var service = new MaskService(new HttpClient()); var maskInfos = await service.GetMaskInfo(); foreach (var maskInfo in maskInfos) { db.Add(new MedicalMask() { Code = maskInfo.醫事機構代碼, Name = maskInfo.醫事機構名稱, Address = maskInfo.醫事機構地址, Tel = maskInfo.醫事機構電話, AdultNum = int.Parse(maskInfo.成人口罩剩餘數), KidNum = int.Parse(maskInfo.兒童口罩剩餘數), UpdateTime = DateTime.Parse(maskInfo.來源資料時間) }); } await db.SaveChangesAsync(); } }
public MaskContext mask() { MaskContext _localctx = new MaskContext(Context, State); EnterRule(_localctx, 10, RULE_mask); try { EnterOuterAlt(_localctx, 1); { State = 70; _localctx.month = Match(NUMBER); State = 71; Match(MINUS); State = 72; _localctx.day = Match(NUMBER); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
public static async Task MaskDataUpdate() { var db = new MaskContext(); var updateTime = db.MedicalMasks.First().UpdateTime; var nextTime = updateTime.AddSeconds(600); var nowTime = DateTime.Now; if (nextTime < nowTime) { var service = new MaskService(new HttpClient()); var maskInfos = await service.GetMaskInfo(); var sourceTime = DateTime.Parse(maskInfos.First().來源資料時間); // 0 is same as value // Ref: https://docs.microsoft.com/en-us/dotnet/api/system.datetime.compareto?view=netcore-3.1#remarks if (sourceTime.CompareTo(updateTime) != 0) { db.RemoveRange(db.MedicalMasks); foreach (var maskInfo in maskInfos) { db.Add(new MedicalMask() { Code = maskInfo.醫事機構代碼, Name = maskInfo.醫事機構名稱, Address = maskInfo.醫事機構地址, Tel = maskInfo.醫事機構電話, AdultNum = int.Parse(maskInfo.成人口罩剩餘數), KidNum = int.Parse(maskInfo.兒童口罩剩餘數), UpdateTime = DateTime.Parse(maskInfo.來源資料時間) }); } await db.SaveChangesAsync(); } } }
public MaskSchedule(MaskContext maskContext, MaskService maskService) { _maskContext = maskContext; _maskService = maskService; }
public MaskController(MaskContext maskContext) { _maskContext = maskContext; }
public MaskController(MaskContext maskContext, MaskService maskService) { _maskContext = maskContext; _maskService = maskService; }