public IActionResult PhysicallyRemove([FromQuery] UserCondition c) { #if DEBUG DataConnection.TurnTraceSwitchOn(); DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context); #endif using (var db = new peppaDB()) { var count = db.User .Where(c.CreatePredicate()) .Delete(); return(Ok(count)); } }
public IActionResult Count([FromQuery] UserCondition c) { #if DEBUG DataConnection.TurnTraceSwitchOn(); DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context); #endif using (var db = new peppaDB()) { var count = c == null?db.User.Count() : db.User.Count(predicate: c.CreatePredicate()); return(Ok(count)); } }
public IActionResult Remove([FromQuery] UserCondition c) { #if DEBUG DataConnection.TurnTraceSwitchOn(); DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context); #endif using (var db = new peppaDB()) { var count = db.User .Where(c.CreatePredicate()) .Set(_ => _.modified_by, CurrentAccountId) .Set(_ => _.removed_at, Sql.CurrentTimestampUtc) .Update(); return(Ok(count)); } }
public IActionResult SearchFull([FromQuery] UserCondition 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.User .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())); } }
public IActionResult Search([FromQuery] UserCondition 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.User .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)); } }