public virtual ItemUser ReturnToStock(ADUser returner) { if (ItemStatus != ItemStatus.OUTSTOCK) { throw new Exception("Can't be returned in this state"); } ItemUser iu = ItemUsers.FirstOrDefault(x => x.ToDate == null); if (iu == null) { if (ADUser != null) { iu = new ItemUser(this, ADUser, returner); ItemUsers.Add(iu); ADUser?.ItemUsers.Add(iu); } } if (iu != null) { iu.Close(returner); } if (ADUser != null) { ADUser.Items.Remove(this); ADUser = null; } ItemStatus = ItemStatus.INSTOCK; return(iu); }
public virtual ItemUser RemoveFromStock(ADUser user, ADUser assigner) { if (ItemStatus.INSTOCK != ItemStatus) { throw new Exception("Can't remove in this state"); } ItemStatus = ItemStatus.OUTSTOCK; var iu = new ItemUser(this, user, assigner); ItemUsers.Add(iu); user?.ItemUsers.Add(iu); ADUser = user; return(iu); }