public IActionResult PhysicallyRemove([FromQuery] PasswordCondition c) { #if DEBUG DataConnection.TurnTraceSwitchOn(); DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context); #endif using (var db = new peppaDB()) { var count = db.Password .Where(c.CreatePredicate()) .Delete(); return(Ok(count)); } }
public IActionResult Count([FromQuery] PasswordCondition c) { #if DEBUG DataConnection.TurnTraceSwitchOn(); DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context); #endif using (var db = new peppaDB()) { var count = c == null?db.Password.Count() : db.Password.Count(predicate: c.CreatePredicate()); return(Ok(count)); } }
public IActionResult Remove([FromQuery] PasswordCondition c) { #if DEBUG DataConnection.TurnTraceSwitchOn(); DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context); #endif using (var db = new peppaDB()) { var count = db.Password .Where(c.CreatePredicate()) .Set(_ => _.modified_by, CurrentAccountId) .Set(_ => _.removed_at, Sql.CurrentTimestampUtc) .Update(); return(Ok(count)); } }
public IActionResult Search([FromQuery] PasswordCondition c, [FromQuery] bool with_Account, [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.Password .LoadWith(with_Account, _ => _.Account) .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)); } }
public IActionResult Change([FromBody] ChangePasswordInputModel inputModel) { #if DEBUG DataConnection.TurnTraceSwitchOn(); DataConnection.WriteTraceLine = (msg, context) => Debug.WriteLine(msg, context); #endif if (ModelState.IsValid) { using (var db = new peppaDB()) { var q = new PasswordCondition { account_id_eq = CurrentAccountId, }; var pw = db.Password.SingleOrDefault(q.CreatePredicate()); if (pw != null) { var new_password = pw.Encrypt(inputModel.Method, inputModel.NewPassword); var new_life = pw.NewLifeExpectancy; var ret = db.Password .Where(q.CreatePredicate()) .Update(_ => new Password { HashType = inputModel.Method, password_hash = new_password, expiration_on = new_life, modified_by = CurrentAccountId, }); return(Ok(ret)); } } } return(BadRequest()); }