コード例 #1
0
        //Leafを編集する権限があるか
        //引数1:アクセスユーザ
        //引数2:DB
        //引数3:編集するleaf
        //戻り値:true 編集可能、false 不可能
        public static async Task <bool> authEditLeaf(ClaimsPrincipal user, ExchaDContext9 context, Leaf leaf)
        {
            bool flag = false;                                           //戻り値:編集可不可フラグ

            Diary diary = await context.diaries.FindAsync(leaf.diaryId); //日記を取得

            if (diary == null)
            {
                return(false);                              //日記がないとき、不可能
            }
            //最新のleafの日時を取得する
            DateTime latest = await context.leaves
                              .Where(l => l.diaryId == leaf.diaryId)
                              .MaxAsync(l => l.time);

            //Leafを編集する権限があるか、確認する
            // 持ち主、かつ、交換中でない、かつ、最新leaf、かつ、コメント者なし、ならば可能

            //未ログインか
            if (!user.Identity.IsAuthenticated)
            {
                //未ログインのとき、不可能
            }                                                                    //ログイン中のとき
            else if (
                (diary.Id == user.FindFirst(ClaimTypes.NameIdentifier).Value) && //日記の持ち主
                (leaf.time == latest) &&                                         //最新leaf
                (diary.retTime < DateTime.Now) &&                                //返却済み
                (leaf.exid == null)                                              //コメント者なし
                )
            {
                flag = true;
            }

            return(flag);
        }
コード例 #2
0
        //Leafへコメントする権限があるか
        //引数1:アクセスユーザ
        //引数2:DB
        //引数3:コメントするleaf
        //戻り値:true コメント可能、false 不可能
        public static async Task <bool> authCommentLeaf(ClaimsPrincipal user, ExchaDContext9 context, Leaf leaf)
        {
            bool flag = false;                                           //戻り値:コメント可不可フラグ

            Diary diary = await context.diaries.FindAsync(leaf.diaryId); //日記を取得

            if (diary == null)
            {
                return(false);                              //日記がないとき、不可能
            }
            //最新のleafの日時を取得する
            DateTime latest = await context.leaves
                              .Where(l => l.diaryId == leaf.diaryId)
                              .MaxAsync(l => l.time);

            //Leafへコメントする権限があるか、確認する
            //交換相手のとき、かつ、最新のLeaf、未コメントleafならば可能

            if (!user.Identity.IsAuthenticated)
            {
                //未ログインのとき、不可能
            }            //ログイン中のとき
            else if (
                (user.FindFirst(ClaimTypes.NameIdentifier).Value == diary.exid) &&              //交換相手
                (leaf.time == latest)                           //最新leaf
                //&& (leaf.exid == null)		//未コメント	//編集可能にする。タイムアップでのみ交換が終了する
                )
            {
                flag = true;
            }
            return(flag);
        }
コード例 #3
0
        //交換申請されているか
        //引数1:アクセスユーザ
        //引数2:DB
        //引数3:相手
        //戻り値:申請されているとき、交換期間。されていないとき、null
        public async static Task <int?> applied(ClaimsPrincipal user, ExchaDContext9 context, Diary diary)
        {
            if (!user.Identity.IsAuthenticated)
            {
                return(null);
            }

            int?period = null;

            string authId = user.FindFirst(ClaimTypes.NameIdentifier).Value;
            //交換申請されているか
            IQueryable <Leaf> leaves = context.leaves.Where(l => l.diaryId == authId);

            if (leaves.Count() != 0)
            {
                DateTime latest = await leaves.MaxAsync(l => l.time);

                Appli appli = context.appli
                              .Where(a =>
                                     (a.diaryId == authId) &&
                                     (a.leafTime == latest) &&
                                     (a.accept == EXCHA_ACCEPT.yet) &&
                                     (a.apid == diary.Id))
                              .FirstOrDefault();
                if (appli != null)
                {
                    period = appli.period;
                }
            }
            return(period);
        }
コード例 #4
0
        public Createテスト()
        {
            var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder
                .AddFilter("XUnitTestProject1", LogLevel.Information)
                .AddFilter("XUnitTestProject1.Createテスト", LogLevel.Information)
                .AddFilter("XUnitTestProject1.Createテスト.Createテスト", LogLevel.Information)
                .AddConsole()
                .AddDebug()
                .AddEventLog();
            });

            _logger = loggerFactory.CreateLogger <CreateModel>();
            _logger.Log(LogLevel.Information, "CreateテストLogger");
            _logger.Log(LogLevel.Warning, "CreateテストLogger");
            _logger.Log(LogLevel.Error, "CreateテストLogger");
            _logger.Log(LogLevel.Debug, "CreateテストLogger");

            var options = new DbContextOptionsBuilder <ExchaDContext9>()
                          .UseInMemoryDatabase(databaseName: "DbName")
                          .Options;

            context = new ExchaDContext9(options);

            //id="dup"を事前登録する
            context.diaries.Add(new Diary("dup", "pass", "note", DateTime.Now, PUBLICITY.pub, EXCHA.able, WRITA.able, DateTime.Now, "exid"));

            model = new CreateModel(_logger, context);
        }
コード例 #5
0
        //最新のleafの日時を取得する
        public static async Task <DateTime?> getLatest(string diaryId, ExchaDContext9 context)
        {
            IQueryable <Leaf> ql = context.leaves.Where(l => l.diaryId == diaryId);

            if (ql.Count() == 0)
            {
                return(null);
            }
            return(await ql.MaxAsync(l => l.time));
        }
コード例 #6
0
        //交換申請可能か
        //引数1:アクセスユーザ
        //引数2:DB
        //引数3:相手の日記
        //戻り値:true 可能
        public async static Task <bool> authExcha(ClaimsPrincipal user, ExchaDContext9 context, Diary diary)
        {
            if (!user.Identity.IsAuthenticated)
            {
                return(false);
            }

            bool flag = false;              //戻り値

            //最新のleafの日時を取得する
            IQueryable <Leaf> ql = context.leaves.Where(l => l.diaryId == diary.Id);

            if (ql.Count() == 0)
            {
                return(false);
            }
            DateTime latest = await ql.MaxAsync(l => l.time);

            string authId = user.FindFirst(ClaimTypes.NameIdentifier).Value;

            Diary my = await context.diaries.FindAsync(authId);

            //自分でない、かつ、両者交換可能、かつ、未申請、かつ、両者交換中でない、ならば申請可能
            //交換可能か
            if ((my.excha == EXCHA.able) &&
                (my.retTime < DateTime.Now) &&
                (diary.excha == EXCHA.able) &&
                (diary.Id != authId) &&
                (diary.retTime < DateTime.Now)
                )
            {
                //未申請か
                flag = !context.appli
                       .Any(a =>
                            (a.diaryId == diary.Id) &&
                            (a.leafTime == latest) &&
                            (a.apid == authId)
                            );
            }
            return(flag);
        }
コード例 #7
0
 public sampleController(ExchaDContext9 context)
 {
     _context = context;
 }
コード例 #8
0
 public testController(ExchaDContext9 context)
 {
     _context = context;
 }
コード例 #9
0
 public AppliController(ExchaDContext9 context)
 {
     _context = context;
 }
コード例 #10
0
 public CreateController(ExchaDContext9 context)
 {
     _context = context;
 }