コード例 #1
0
        public IActionResult PhysicallyRemove([FromQuery] TeacherCondition c)
        {
#if DEBUG
            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context);
#endif
            using (var db = new peppaDB())
            {
                var count = db.Teacher
                            .Where(c.CreatePredicate())
                            .Delete();
                return(Ok(count));
            }
        }
コード例 #2
0
        public IActionResult Count([FromQuery] TeacherCondition c)
        {
#if DEBUG
            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context);
#endif
            using (var db = new peppaDB())
            {
                var count =
                    c == null?db.Teacher.Count() :
                        db.Teacher.Count(predicate: c.CreatePredicate());

                return(Ok(count));
            }
        }
コード例 #3
0
        public IActionResult Remove([FromQuery] TeacherCondition c)
        {
#if DEBUG
            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context);
#endif
            using (var db = new peppaDB())
            {
                var count = db.Teacher
                            .Where(c.CreatePredicate())
                            .Set(_ => _.modified_by, CurrentAccountId)
                            .Set(_ => _.removed_at, Sql.CurrentTimestampUtc)
                            .Update();
                return(Ok(count));
            }
        }
コード例 #4
0
        public IActionResult Search([FromQuery] TeacherCondition c, [FromQuery] bool with_WorkStyle, [FromQuery] bool with_Position, [FromQuery] bool with_TeacherLisence, [FromQuery] bool with_SexType, [FromQuery] bool with_AccountList, [FromQuery] bool with_NameList, [FromQuery] bool with_AddressList, [FromQuery] bool with_ContactList, [FromQuery] string[] order, int currentPage = 1, int pageSize = 10, DateTime?p_when = null)
        {
#if DEBUG
            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context);
#endif
            using (var db = new peppaDB())
            {
                var q = db.Teacher
                        .LoadWith(with_WorkStyle, _ => _.WorkStyle)
                        .LoadWith(with_Position, _ => _.Position)
                        .LoadWith(with_TeacherLisence, _ => _.TeacherLisence)
                        .LoadWith(with_SexType, _ => _.SexType)
                        .LoadWith(with_AccountList, _ => _.AccountList)
                        .LoadWith(with_NameList, _ => _.NameList)
                        .LoadWith(with_AddressList, _ => _.AddressList)
                        .LoadWith(with_ContactList, _ => _.ContactList)
                        .IsActiveAt(p_when)
                ;
                var filtered = c == null ? q : q.Where(c.CreatePredicate());
                var ordered  = order.Any() ? filtered.SortBy(order) : filtered;
                var result   = ordered.Skip((currentPage - 1) * pageSize).Take(pageSize).ToList();

                #region アソシエーションでLoadWithしたものもフィルタする
                if (p_when != null)
                {
                    result.ForEach(_ =>
                    {
                        _.AccountList = _.AccountList?.Where(_ => _.IsActiveAt(p_when));
                        _.NameList    = _.NameList?.Where(_ => _.IsActiveAt(p_when));
                        _.AddressList = _.AddressList?.Where(_ => _.IsActiveAt(p_when));
                        _.ContactList = _.ContactList?.Where(_ => _.IsActiveAt(p_when));
                    });
                }
                #endregion

                return(Ok(result));
            }
        }
コード例 #5
0
        public IActionResult SearchFull([FromQuery] TeacherCondition c, [FromQuery] string[] order, int currentPage = 1, int pageSize = 10)
        {
#if DEBUG
            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context);
#endif
            using (var db = new peppaDB())
            {
                var q = db.Teacher
                        .LoadWith(_ => _.SexType)
                        .LoadWith(_ => _.WorkStyle)
                        .LoadWith(_ => _.Position)
                        .LoadWith(_ => _.TeacherLisence)
                        .LoadWith(_ => _.NameList.First().PersonNameType)
                        .LoadWith(_ => _.AddressList.First().AddressType)
                        .LoadWith(_ => _.ContactList.First().ContactType);

                var filtered = c == null ? q : q.Where(c.CreatePredicate());
                var ordered  = order.Any() ? filtered.SortBy(order) : filtered;

                return(Ok(ordered.Skip((currentPage - 1) * pageSize).Take(pageSize).ToList()));
            }
        }