Beispiel #1
0
        public IEnumerable <Address> Search([FromUri] bool with_AddressType, [FromUri] bool with_Staff, [FromUri] AddressCondition c)
        {
#if DEBUG
            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context);
#endif
            using (var db = new peppaDB())
            {
                var q = db.Address;

                #region LoadWith
                if (with_AddressType)
                {
                    q = q.LoadWith(_ => _.AddressType);
                }
                if (with_Staff)
                {
                    q = q.LoadWith(_ => _.Staff);
                }
                #endregion

                var list = (c == null ? q : q.Where(c.CreatePredicate())).ToList();
                return(list);
            }
        }
        public IActionResult Remove([FromQuery] AddressCondition c)
        {
#if DEBUG
            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context);
#endif
            using (var db = new peppaDB())
            {
                var count = db.Address
                            .Where(c.CreatePredicate())
                            .Delete();
                return(Ok(count));
            }
        }
        public IActionResult Count([FromQuery] AddressCondition c)
        {
#if DEBUG
            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context);
#endif
            using (var db = new peppaDB())
            {
                var count =
                    c == null?db.Address.Count() :
                        db.Address.Count(predicate: c.CreatePredicate());

                return(Ok(count));
            }
        }
        public IActionResult Search([FromQuery] AddressCondition c, [FromQuery] bool with_AddressType, [FromQuery] bool with_Staff, [FromQuery] bool with_Teacher, [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.Address
                        .LoadWith(with_AddressType, _ => _.AddressType)
                        .LoadWith(with_Staff, _ => _.Staff)
                        .LoadWith(with_Teacher, _ => _.Teacher)
                        .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();
                return(Ok(result));
            }
        }