public void UpdateForOrder(long orderId, OrderNotifyType notifyType, IList <OrderNotifyDto> notifies, DateTime when) { notifies = notifies ?? new List <OrderNotifyDto>(); var dbExistNotifies = GetAll() .Where(n => n.OrderId == orderId && n.Type == (int)notifyType) .ToList(); foreach (var notify in notifies) { var dbExist = dbExistNotifies.FirstOrDefault(n => n.Message == notify.Message); if (dbExist == null) { dbExist = new OrderNotify() { OrderId = orderId, CreateDate = when, Type = (int)notifyType, Status = 1, Message = notify.Message, Params = notify.Params, }; Add(dbExist); unitOfWork.Commit(); } notify.Id = dbExist.Id; } var toRemoveNotifies = dbExistNotifies.Where(n => !notifies.Any(newN => newN.Id == n.Id)).ToList(); foreach (var toRemove in toRemoveNotifies) { Remove(toRemove); } unitOfWork.Commit(); }
public bool IsExist(long orderId, OrderNotifyType notifyType) { return(GetAll().Any(n => n.OrderId == orderId && n.Type == (int)notifyType)); }