Esempio n. 1
0
        public int PhysicallyRemove([FromUri] StaffCondition c)
        {
#if DEBUG
            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context);
#endif
            using (var db = new peppaDB())
            {
                var count = db.Staff
                            .Where(c.CreatePredicate())
                            .Delete();
                return(count);
            }
        }
Esempio n. 2
0
        public int Count([FromUri] StaffCondition c)
        {
#if DEBUG
            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context);
#endif
            using (var db = new peppaDB())
            {
                var count =
                    c == null?db.Staff.Count() :
                        db.Staff.Count(predicate: c.CreatePredicate());

                return(count);
            }
        }
Esempio n. 3
0
        public int Remove([FromUri] StaffCondition c)
        {
#if DEBUG
            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context);
#endif
            using (var db = new peppaDB())
            {
                var count = db.Staff
                            .Where(c.CreatePredicate())
                            .Set(_ => _.removed_at, Sql.CurrentTimestampUtc)
                            .Update();
                return(count);
            }
        }
Esempio n. 4
0
        public IActionResult SearchFull([FromQuery] StaffCondition 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.Staff
                        .LoadWith(_ => _.SexType)
                        .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()));
            }
        }
Esempio n. 5
0
        public IActionResult Search([FromQuery] StaffCondition c, [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.Staff
                        .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));
            }
        }
Esempio n. 6
0
        public IEnumerable <Staff> Search([FromUri] bool with_AccountList, [FromUri] bool with_NameList, [FromUri] bool with_AddressList, [FromUri] bool with_ContactList, [FromUri] StaffCondition c)
        {
#if DEBUG
            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context);
#endif
            using (var db = new peppaDB())
            {
                var q = db.Staff;

                #region LoadWith
                if (with_AccountList)
                {
                    q = q.LoadWith(_ => _.AccountList);
                }
                if (with_NameList)
                {
                    q = q.LoadWith(_ => _.NameList);
                }
                if (with_AddressList)
                {
                    q = q.LoadWith(_ => _.AddressList);
                }
                if (with_ContactList)
                {
                    q = q.LoadWith(_ => _.ContactList);
                }
                #endregion

                var list = (c == null ? q : q.Where(c.CreatePredicate())).ToList();
                return(list);
            }
        }