public Appli(string diaryId, DateTime leafTime, string apid, EXCHA_ACCEPT accept) { this.diaryId = diaryId; this.leafTime = leafTime; this.apid = apid; this.accept = accept; }
public async Task <bool> reply(EXCHA_ACCEPT excha, string exid, string token) { //POSTデータを取得する var form = HttpContext.Request.Form; Microsoft.Extensions.Primitives.StringValues value; form.TryGetValue("excha", out value); if (value.ToString() == "accept") { excha = EXCHA_ACCEPT.accept; } else if (value.ToString() == "reject") { excha = EXCHA_ACCEPT.reject; } form.TryGetValue("exid", out value); exid = value.ToString(); form.TryGetValue("token", out value); token = value.ToString(); if (!PBKDF2.Verify(HttpContext.User.FindFirst(ClaimTypes.Sid).Value, token)) { return(false); } //日記の情報を取得する Diary diary = await _context.diaries.FindAsync(exid); if (diary == null) { return(false); } //日記が存在するとき //交換可能か if (!await DiaryAuth.authExcha(HttpContext.User, _context, diary)) { return(false); } //交換可能なとき //appliへ承諾を登録 //お互いの日記に交換相手を記録 //返却日時の記録 //appliへ承諾を登録 string authId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; DateTime latest = await _context.leaves .Where(l => l.diaryId == authId) .MaxAsync(l => l.time); Appli appli = await _context.appli .Where(a => (a.diaryId == authId) && (a.leafTime == latest) && (a.apid == exid) ) .FirstOrDefaultAsync(); appli.accept = excha; _context.Attach(appli).State = EntityState.Modified; if (excha == EXCHA_ACCEPT.accept) { //承諾のとき //お互いの日記に交換を記録 Diary my = await _context.diaries.FindAsync(authId); Diary your = await _context.diaries.FindAsync(appli.apid); my.exid = your.Id; my.retTime = DateTime.Now.AddHours(appli.period); your.exid = my.Id; your.retTime = DateTime.Now.AddHours(appli.period); _context.Attach(my).State = EntityState.Modified; _context.Attach(your).State = EntityState.Modified; } await _context.SaveChangesAsync(); return(true); }