public UserLSet AddToInventory(int userId, int setId, int pieces) { var user = userRepository.GetById(userId); if (user != null) { var dbSet = lSetRepository.GetById(setId); if (dbSet != null) { var existingWishListItem = wishlistRepository.Query().FirstOrDefault(x => x.User.Id == userId && x.LSet.Id == setId); if (existingWishListItem != null) { existingWishListItem.Number -= pieces; wishlistRepository.Save(existingWishListItem); } var existingInventroyItem = inventoryRepository.Query().FirstOrDefault(x => x.User.Id == userId && x.LSet.Id == setId); if (existingInventroyItem == null) { var inventoryForSave = new UserLSet() { User = user, LSet = dbSet, Built = 0, Owned = pieces }; inventoryRepository.Save(inventoryForSave); return(inventoryForSave); } else { existingInventroyItem.Owned += pieces; inventoryRepository.Save(existingInventroyItem); return(existingInventroyItem); } } else { throw new DataException("Set not found!"); } } throw new UserException(UserException.UserExceptionsText(UserExceptionEnum.NotFound)); }
public void SaveOrUpdate(UserLSet set) { inventoryRepository.Save(set); }