private void AddOrUpdateCard(CardInfo card) { var repo = new BaseRepo <CardInfo>(dbCtx); CardInfo existsCard = null; if (!string.IsNullOrEmpty(card.PkId)) { existsCard = repo.Find(card.PkId); } else if (!string.IsNullOrEmpty(card.CardNo)) { existsCard = repo.Find(t => t.CardNo == card.CardNo).FirstOrDefault(); } card.UpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); if (existsCard == null) { card.NewId(); repo.Add(card); } else { existsCard.UpdateTime = card.UpdateTime; existsCard.User = card.User; existsCard.SerialNo = card.SerialNo; existsCard.CardType = card.CardType; existsCard.InvalidDate = card.InvalidDate; repo.Update(existsCard); card.PkId = existsCard.PkId; } }
private void AddOrUpdateUser(UserInfo user) { var repo = new BaseRepo <UserInfo>(dbCtx); UserInfo existsUser = null; if (!string.IsNullOrEmpty(user.PkId)) { existsUser = repo.Find(user.PkId); } else if (!string.IsNullOrEmpty(user.IdentityNumber)) { existsUser = repo.Find(t => t.IdentityNumber == user.IdentityNumber).FirstOrDefault(); } if (existsUser == null) { user.NewId(); repo.Add(user); } else { existsUser.Name = user.Name; existsUser.Phone = user.Phone; existsUser.IdentityNumber = user.IdentityNumber; //todo: other fields user.PkId = existsUser.PkId; repo.Update(existsUser); } }
private void UpdateAuth(string cardPkId, IList <Device> devices) { var repo = new BaseRepo <CardAuth>(dbCtx); var existsList = repo.Find(t => t.Card == cardPkId); foreach (var e in existsList) { repo.Delete(e); } if (devices != null && devices.Count > 0) { var updateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); foreach (var dev in devices) { var entity = new CardAuth() { Card = cardPkId, Device = dev.PkId, UpdateTime = updateTime }; entity.NewId(); repo.Add(entity); } } }
public void Get(Guid id) { repo.Find(id); }