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

                return(count);
            }
        }
Exemplo n.º 3
0
        public IActionResult Search([FromQuery] ContactCondition c, [FromQuery] bool with_ContactType, [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.Contact
                        .LoadWith(with_ContactType, _ => _.ContactType)
                        .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));
            }
        }
Exemplo n.º 4
0
        public IEnumerable <Contact> Search([FromUri] bool with_ContactType, [FromUri] bool with_Staff, [FromUri] ContactCondition c)
        {
#if DEBUG
            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context);
#endif
            using (var db = new peppaDB())
            {
                var q = db.Contact;

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

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